m4gr3d / Godot-Android-Samples

Collection of Godot Android plugins
MIT License
43 stars 6 forks source link

java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/coroutines/SupervisorKt; #13

Closed kyadalu1 closed 10 months ago

kyadalu1 commented 11 months ago

I am trying to use Kotlin's coroutine in my android library for Godot. Below is the complete error message

Process: com.example.mygodotapp, PID: 21586
                                                                                                    java.lang.NoClassDefFoundError: Failed resolution of: Lkotlinx/coroutines/SupervisorKt;
                                                                                                        at com.example.androidlocation.LocationService.<init>(LocationService.kt:21)
                                                                                                        at java.lang.Class.newInstance(Native Method)
                                                                                                        at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129)
                                                                                                        at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:75)
                                                                                                        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4922)
                                                                                                        at android.app.ActivityThread.access$1800(ActivityThread.java:310)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2300)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:226)
                                                                                                        at android.os.Looper.loop(Looper.java:313)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8669)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
                                                                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "kotlinx.coroutines.SupervisorKt" on path: DexPathList[[zip file "/data/app/~~ODYQy-wm45_J8E3bkTjOVA==/com.example.mygodotapp-TDcRajdFrZrn0B_hub7hLA==/base.apk"],nativeLibraryDirectories=[/data/app/~~ODYQy-wm45_J8E3bkTjOVA==/com.example.mygodotapp-TDcRajdFrZrn0B_hub7hLA==/lib/arm, /data/app/~~ODYQy-wm45_J8E3bkTjOVA==/com.example.mygodotapp-TDcRajdFrZrn0B_hub7hLA==/base.apk!/lib/armeabi-v7a, /system/lib, /system/system_ext/lib]]
                                                                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                                        at com.example.androidlocation.LocationService.<init>(LocationService.kt:21) 
                                                                                                        at java.lang.Class.newInstance(Native Method) 
                                                                                                        at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129) 
                                                                                                        at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:75) 
                                                                                                        at android.app.ActivityThread.handleCreateService(ActivityThread.java:4922) 
                                                                                                        at android.app.ActivityThread.access$1800(ActivityThread.java:310) 
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2300) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106) 
                                                                                                        at android.os.Looper.loopOnce(Looper.java:226) 
                                                                                                        at android.os.Looper.loop(Looper.java:313) 
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8669) 
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) 

Here is the my android library repo and here is the Godot repo

My code crashes when i try to use below code in my android library

private val serviceScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)

I am using kotlin 1.9.10 which contain coroutines internally and i have not added any coroutines dependencies externally

kyadalu1 commented 11 months ago

Use Java 17

compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
kyadalu1 commented 11 months ago

Nah same issue

kyadalu1 commented 11 months ago

I face similar issue when i don't use coroutines but i add some third party library to my android library. I try to add the biometric androdi x library, and when i call it from Godot i get issue

FATAL EXCEPTION: main
                                                                                                    Process: com.example.mygame, PID: 11183
                                                                                                    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/biometric/BiometricManager;
                                                                                                        at com.example.androidlibrary.GodotAndroidPlugin.authenticate$lambda$4$lambda$3(GodotAndroidPlugin.kt:70)
                                                                                                        at com.example.androidlibrary.GodotAndroidPlugin.$r8$lambda$EAioTuHWHUp3Q45fI013PsNpbY8(Unknown Source:0)
                                                                                                        at com.example.androidlibrary.GodotAndroidPlugin$$ExternalSyntheticLambda1.run(Unknown Source:2)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:938)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:226)
                                                                                                        at android.os.Looper.loop(Looper.java:313)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8669)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
                                                                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.biometric.BiometricManager" on path: DexPathList[[zip file "/data/app/~~c2LDRqR1AK6x59f8Ur7Qkg==/com.example.mygame-TIC2DKBf9zoKLE_L0YlphQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~c2LDRqR1AK6x59f8Ur7Qkg==/com.example.mygame-TIC2DKBf9zoKLE_L0YlphQ==/lib/arm, /data/app/~~c2LDRqR1AK6x59f8Ur7Qkg==/com.example.mygame-TIC2DKBf9zoKLE_L0YlphQ==/base.apk!/lib/armeabi-v7a, /system/lib, /system/system_ext/lib]]
                                                                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                                        at com.example.androidlibrary.GodotAndroidPlugin.authenticate$lambda$4$lambda$3(GodotAndroidPlugin.kt:70) 
                                                                                                        at com.example.androidlibrary.GodotAndroidPlugin.$r8$lambda$EAioTuHWHUp3Q45fI013PsNpbY8(Unknown Source:0) 
                                                                                                        at com.example.androidlibrary.GodotAndroidPlugin$$ExternalSyntheticLambda1.run(Unknown Source:2) 
                                                                                                        at android.os.Handler.handleCallback(Handler.java:938) 
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                                        at android.os.Looper.loopOnce(Looper.java:226) 
                                                                                                        at android.os.Looper.loop(Looper.java:313) 
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8669) 
                                                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
m4gr3d commented 10 months ago

@kyadalu1 I provided an answer in https://github.com/godotengine/godot/issues/86152#issuecomment-1865273113; Kotlin coroutines are a separate dependency so you need to include that dependency to avoid ClassNotFoundException exception errors.

See https://developer.android.com/kotlin/coroutines#dependency for more details.

kyadalu1 commented 10 months ago

@m4gr3d Can you check this comment