Skip to content

Fallback to standard Bundle access when running outside JNI environment#28

Merged
marcprux merged 1 commit into
mainfrom
no-jni-fallback
Jun 22, 2026
Merged

Fallback to standard Bundle access when running outside JNI environment#28
marcprux merged 1 commit into
mainfrom
no-jni-fallback

Conversation

@marcprux

@marcprux marcprux commented Jun 22, 2026

Copy link
Copy Markdown
Member

When testing a Skip Fuse module that tries to access Bundle.module via skip android test, the following crash would happen:

SwiftJNI/SwiftJNI.swift:72: Precondition failed: JNI.jni was unset
Current stack trace:
0    libswiftCore.so                    0x00000074229f0304 swift_reportError + 44
1    libswiftCore.so                    0x0000007422a8a134 _swift_stdlib_reportFatalErrorInFile + 128
2    libswiftCore.so                    0x0000007422743980 <unavailable> + 1841536
3    libswiftCore.so                    0x000000742289c364 _assertionFailure(_:_:file:line:flags:) + 160
4    libSwiftJNI.so                     0x000000741c90b880 jniContext<A>(_:) + 312
5    libSkipAndroidBridge.so            0x00000074359aba7c static BundleAccess.main.getter + 64
6    libSkipAndroidBridge.so            0x000000743599f160 <unavailable> + 774496
7    libswiftCore.so                    0x0000007422a8b8c8 <unavailable> + 5281992
8    libSkipAndroidBridge.so            0x000000743599f11c <unavailable> + 774428
9    libSkipAndroidBridge.so            0x00000074359a05f4 static AndroidBundle.main.getter + 24
10   SkipLocalizationJNIReproPackageTests.xctest 0x000000623ec4eb68 <unavailable> + 76648
11   SkipLocalizationJNIReproPackageTests.xctest 0x000000623ec4ef04 <unavailable> + 77572
12   libswiftCore.so                    0x0000007422a8b8c8 <unavailable> + 5281992
13   SkipLocalizationJNIReproPackageTests.xctest 0x000000623ec4ef30 <unavailable> + 77616
14   SkipLocalizationJNIReproPackageTests.xctest 0x000000623ec4eab8 <unavailable> + 76472
15   SkipLocalizationJNIReproPackageTests.xctest 0x000000623ec7a220 <unavailable> + 254496
16   SkipLocalizationJNIReproPackageTests.xctest 0x000000623ec79b48 <unavailable> + 252744
17   libswift_Concurrency.so            0x000000743058ed34 <unavailable> + 552244
18   libswift_Concurrency.so            0x000000743058f978 swift_job_run + 164
19   libdispatch.so                     0x000000741c68c448 <unavailable> + 226376
20   libdispatch.so                     0x000000741c68c28c <unavailable> + 225932
21   libdispatch.so                     0x000000741c6966e8 <unavailable> + 268008
22   libc.so                            0x000000742f3546ac <unavailable> + 833196
23   libc.so                            0x000000742f2f1220 <unavailable> + 426528
Trap 

Error: Error terminated(code: 1) running command: /Users/marc/Library/Android/sdk/platform-tools/adb shell cd '/data/local/tmp/swift-android/SkipLocalizationJNIRepro-8AF0F2E3-AAFA-4411-890D-8411EAC2E893/' && ./SkipLocalizationJNIReproPackageTests.xctest && ./SkipLocalizationJNIReproPackageTests.xctest --testing-library swift-testing && [ $? -eq 0 ] || [ $? -eq 69 ]

As discussed at https://skip.dev/docs/testing/, skip android test is a "bare-bones" testing tool, in that it runs the tests as a bare native Android executable, rather than bundling everything into an .apk and executing instrumented tests like skip test --android-serial=emulator-5554 does.

This is normally fine, but when the module under test incorporates Skip by using the skipstone plugin, then we generate a shim to intercept bundle access and redirect it to Skip's bridged Bundle support, which integrates with our packaging of the SwiftPM resources into the apk's assets/ folder and uses the AssetManager to retrieve these resources. None of this happens at all under the bare metal testing of skip android test, and so it doesn't work: we crash when we first try to bridge through to Skip because there is no ambient java environment in this scenario.

This PR provides a stopgap that bypasses bridging and falls back to the default Linux-style .resources/ folder handling that a non-Skip project would use.

@cla-bot cla-bot Bot added the cla-signed label Jun 22, 2026
@marcprux marcprux merged commit 51211da into main Jun 22, 2026
3 checks passed
@marcprux marcprux deleted the no-jni-fallback branch June 22, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant