slint icon indicating copy to clipboard operation
slint copied to clipboard

Andorid 9: panicked with 'java.lang.ClassNotFoundException'

Open wg138940 opened this issue 3 months ago • 2 comments

Platform: Android Language: Rust

Reproduce steps:

Project source code: slint-android-test.zip

build project with xbuild (or cargo-apk):

x build --arch arm64 --platform android --offline --format apk

install and launch APP on Android 9 (with BlueStacks 5 Emulator), will produce error:

03-24 21:23:11.649  3864  3884 W System.err: java.lang.ClassNotFoundException: Didn't find class "SlintAndroidJavaHelper" on path: DexPathList[[dex file "InMemoryDexFile[cookie=[0, 127278808428096]]"],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64]]
03-24 21:23:11.651  3864  3884 W System.err:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
03-24 21:23:11.653  3864  3884 W System.err:    Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/Object;
03-24 21:23:11.654  3864  3884 W System.err:            at dalvik.system.DexFile.defineClassNative(Native Method)
03-24 21:23:11.654  3864  3884 W System.err:            at dalvik.system.DexFile.defineClass(DexFile.java:283)
03-24 21:23:11.655  3864  3884 W System.err:            at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:276)
03-24 21:23:11.655  3864  3884 W System.err:            at dalvik.system.DexPathList$Element.findClass(DexPathList.java:724)
03-24 21:23:11.655  3864  3884 W System.err:            at dalvik.system.DexPathList.findClass(DexPathList.java:486)
03-24 21:23:11.655  3864  3884 W System.err:            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:132)
03-24 21:23:11.656  3864  3884 W System.err:    Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.Object" on path: DexPathList[[dex file "InMemoryDexFile[cookie=[0, 127278808428096]]"],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64]]
03-24 21:23:11.657  3864  3884 W System.err:            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
03-24 21:23:11.660  3864  3884 W System.err:            at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
03-24 21:23:11.662  3864  3884 W System.err:            at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
03-24 21:23:11.663  3864  3884 W System.err:            ... 6 more
03-24 21:23:11.668  3864  3883 I RustStdoutStderr: thread '<unnamed>' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/i-slint-backend-android-activity-1.5.1/androidwindowadapter.rs:134:68:
03-24 21:23:11.669  3864  3883 I RustStdoutStderr: JNI error: JavaException
03-24 21:23:11.669  3864  3883 I RustStdoutStderr: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
03-24 21:23:11.675  3864  3884 E RustPanic: JNI error: JavaException

same APK works on Andorid 12 (with another emulator and real Android device): image

wg138940 avatar Mar 24 '24 14:03 wg138940

Thanks for the bug report. Someone else actually had reported this issue with Android 9 before. I don't know the reason behind the error though. The SlintAndroidJavaHelper class clearly exist. Maybe we're calling into API that did not exist in Android 9, but I don't know which ones.

ogoffart avatar Mar 25 '24 10:03 ogoffart

The error message also mentions a failure to find the class java.lang.Object, which is a fundamental class in Java and should always be available.

The InMemoryDexClassLoader which we used was added in API level 26, which is Android 8.0. And I've tried to be carefull not to use anything that use a higher API level. I'd like to be able to support Android 8 and 9 since they still amount for about 11% of users according to https://apilevels.com/

Any help to tackle this issue would be welcome.

ogoffart avatar Mar 25 '24 11:03 ogoffart