Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wg138940 opened this issue Mar 24, 2024 · 4 comments
Open

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

wg138940 opened this issue Mar 24, 2024 · 4 comments
Labels
a:platform-android Android platform integration (mO,bS) bug Something isn't working

Comments

@wg138940
Copy link

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

@ogoffart
Copy link
Member

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 ogoffart added bug Something isn't working a:platform-android Android platform integration (mO,bS) labels Mar 25, 2024
@ogoffart ogoffart changed the title Andorid backend panicked with 'java.lang.ClassNotFoundException' Andorid 9: panicked with 'java.lang.ClassNotFoundException' Mar 25, 2024
@ogoffart
Copy link
Member

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.

@wuwbobo2021
Copy link

What's the lowest supported Android version at this moment?

Platform: Android 8.0
Slint version: 1.8.0
Probably the same problem. I don't know how to debug the Slint app on Android, but here's the logcat segment:

10-03 01:17:25.417 E/AndroidRuntime( 676): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
10-03 01:17:25.417 E/AndroidRuntime( 676): ... 6 more
10-03 01:17:25.417 E/AndroidRuntime( 676): java.lang.ClassNotFoundException: Didn't find class "SlintAndroidJavaHelper" on path: DexPathList[[dex file "InMemoryDexFile[cookie=[0, 523841617184]]"],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64]]
10-03 01:17:25.417 E/AndroidRuntime( 676): Process: rust.calculator_rs, PID: 676
10-03 01:17:25.417 E/AndroidRuntime( 676): FATAL EXCEPTION: Thread-3
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
10-03 01:17:25.417 E/AndroidRuntime( 676): Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/Object;
10-03 01:17:25.417 E/AndroidRuntime( 676): Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.Object" on path: DexPathList[[dex file "InMemoryDexFile[cookie=[0, 523841617184]]"],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64]]
10-03 01:17:25.417 E/AndroidRuntime( 676): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.DexPathList.findClass(DexPathList.java:466)
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.DexPathList$Element.findClass(DexPathList.java:677)
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:275)
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.DexFile.defineClassNative(Native Method)
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.DexFile.defineClass(DexFile.java:282)
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
10-03 01:17:25.417 E/AndroidRuntime( 676): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:91)
10-03 01:17:25.415 W/System.err( 676): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
10-03 01:17:25.415 W/System.err( 676): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
10-03 01:17:25.415 W/System.err( 676): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
10-03 01:17:25.415 W/System.err( 676): ... 6 more
10-03 01:17:25.415 I/RustStdoutStderr( 676): thread '<unnamed>' panicked at C:\Users\net\.cargo\registry\src\rsproxy.cn-0dccff568467c15b\i-slint-backend-android-activity-1.8.0\androidwindowadapter.rs:171:68:
10-03 01:17:25.415 I/RustStdoutStderr( 676): note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
10-03 01:17:25.415 I/RustStdoutStderr( 676): JNI error: JavaException
10-03 01:17:25.415 E/RustPanic( 676): JNI error: JavaException
10-03 01:17:25.414 W/System.err( 676): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
10-03 01:17:25.414 W/System.err( 676): Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/Object;
10-03 01:17:25.414 W/System.err( 676): Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.Object" on path: DexPathList[[dex file "InMemoryDexFile[cookie=[0, 523841617184]]"],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64]]
10-03 01:17:25.414 W/System.err( 676): at dalvik.system.DexPathList.findClass(DexPathList.java:466)
10-03 01:17:25.414 W/System.err( 676): at dalvik.system.DexPathList$Element.findClass(DexPathList.java:677)
10-03 01:17:25.414 W/System.err( 676): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:275)
10-03 01:17:25.414 W/System.err( 676): at dalvik.system.DexFile.defineClassNative(Native Method)
10-03 01:17:25.414 W/System.err( 676): at dalvik.system.DexFile.defineClass(DexFile.java:282)
10-03 01:17:25.414 W/System.err( 676): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:91)
10-03 01:17:25.413 W/System.err( 676): java.lang.ClassNotFoundException: Didn't find class "SlintAndroidJavaHelper" on path: DexPathList[[dex file "InMemoryDexFile[cookie=[0, 523841617184]]"],nativeLibraryDirectories=[/system/lib64, /system/vendor/lib64]]
10-03 01:17:25.412 V/ALMOND ( 676): Almond_Is_DRMDex() : Entering
10-03 01:17:25.352 D/PhoneWindow( 676): windowLightStatusBar : false, disable View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
10-03 01:17:25.352 D/DecorView( 2238): updateNavigationGuardColor navigationGuardColor=0xffe9ebee
10-03 01:17:25.352 D/ViewRootImpl( 2238): onChangedNavigationGuardColor(), color: ffe9ebee
10-03 01:17:25.294 I/zygote64( 676): Increasing code cache capacity to 128KB
10-03 01:17:25.294 I/zygote64( 676): After code cache collection, code=29KB, data=21KB
10-03 01:17:25.294 I/zygote64( 676): Do partial code cache collection, code=29KB, data=21KB
10-03 01:17:25.284 V/APM_AudioPolicyManager( 843): setOutputDevice() setting same device 0x0000 or null device
10-03 01:17:25.284 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 8, device 2
10-03 01:17:25.284 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 7, device 2
10-03 01:17:25.283 V/AudioPolicyManagerEx( 843): getNewOutputDevice() selected device 0
10-03 01:17:25.283 V/APM_AudioPolicyManager( 843): setOutputDevice() prevDevice 0x0002
10-03 01:17:25.283 V/APM_AudioPolicyManager( 843): setOutputDevice() device 0000 delayMs 96
10-03 01:17:25.283 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 6, device 2
10-03 01:17:25.283 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 5, device 2
10-03 01:17:25.283 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 4, device 2
10-03 01:17:25.283 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 3, device 2
10-03 01:17:25.283 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 2, device 2
10-03 01:17:25.283 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 1, device 1
10-03 01:17:25.283 V/APM::AudioPolicyEngine( 843): getDeviceForStrategy() strategy 0, device 2
10-03 01:17:25.283 V/APM::AudioOutputDescriptor( 843): changeRefCount() stream 1, count 0
10-03 01:17:25.283 V/APM_AudioPolicyManager( 843): stopOutput() output 13, stream 1, session 521
10-03 01:17:25.272 V/AudioFlinger_Threads( 843): removeTracks_l removing track on session 521
10-03 01:17:25.269 V/audio_hw_primary( 843): out_get_latency: Latency 8
10-03 01:17:25.256 W/System ( 676): ClassLoader referenced unknown path:
10-03 01:17:25.253 W/ActivityThread( 676): Application rust.calculator_rs can be debugged on port 8100...

@ogoffart
Copy link
Member

ogoffart commented Oct 3, 2024

The way it works is that it tries to load the SlintAndroidJavaHelper class here


That class should exist because it is jenerated by the build script from a .java file

I don't know what the problem is. Maybe the build script generated some bytecode that is not compatible with android 8? Maybe the java file contains things that prevent it to be loaded on android 8? Maybe InMemoryDexClassLoader doesn't work correctly on android 8?

Any help to debug why exactly it is failing would be welcome

What's the lowest supported Android version at this moment?

I think people have used it fine on Android 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:platform-android Android platform integration (mO,bS) bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants