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

'NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory' in kotlin multiplatform for android target #432

Closed
sgpublic opened this issue Jul 10, 2024 · 2 comments

Comments

@sgpublic
Copy link

Reproduce step:

  1. Create a new "Kotlin Multiplatform App" with Android Studio.
  2. Edit <rootProject>/shared/build.gradle.kts, add implementation("io.github.oshai:kotlin-logging:7.0.0"):
       listOf(
           iosX64(),
           iosArm64(),
           iosSimulatorArm64()
       ).forEach {
           it.binaries.framework {
               baseName = "shared"
               isStatic = true
           }
       }
     
       sourceSets {
           commonMain.dependencies {
               implementation("io.github.oshai:kotlin-logging:7.0.0") // add this line
               //put your multiplatform dependencies here
           }
           commonTest.dependencies {
               implementation(libs.kotlin.test)
           }
       }
  3. Edit Greeting.kt in commonMain:
     class Greeting {
         private val platform: Platform = getPlatform()
         private val logger = KotlinLogging.logger("Greeting") // add this line
     
         fun greet(): String {
             logger.debug { "Greeting#greet" } // add this line
             return "Hello, ${platform.name}!"
         }
     }
  4. sync project, run androidApp directly, app crashed:
     18:44:24.922  E  System zygote died with fatal exception
                      java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
                  	    at io.github.oshai.kotlinlogging.slf4j.internal.Slf4jLoggerFactory.jLogger$kotlin_logging_debug(Slf4jLoggerFactory.kt:11)
                  	    at io.github.oshai.kotlinlogging.internal.KLoggerFactory.logger$kotlin_logging_debug(KLoggerFactory.kt:13)
                  	    at io.github.oshai.kotlinlogging.KotlinLogging.logger(KotlinLogging.kt:24)
                  	    at io.github.sgpublic.kotlinloggingtest.Greeting.<init>(Greeting.kt:7)
                  	    at io.github.sgpublic.kotlinloggingtest.android.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:22)
                  	    at io.github.sgpublic.kotlinloggingtest.android.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:21)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.material3.SurfaceKt$Surface$1.invoke(Surface.kt:132)
                  	    at androidx.compose.material3.SurfaceKt$Surface$1.invoke(Surface.kt:114)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
                  	    at androidx.compose.material3.SurfaceKt.Surface-T9BRK9s(Surface.kt:111)
                  	    at io.github.sgpublic.kotlinloggingtest.android.ComposableSingletons$MainActivityKt$lambda-2$1.invoke(MainActivity.kt:18)
                  	    at io.github.sgpublic.kotlinloggingtest.android.ComposableSingletons$MainActivityKt$lambda-2$1.invoke(MainActivity.kt:17)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
                  	    at androidx.compose.material3.TextKt.ProvideTextStyle(Text.kt:360)
                  	    at androidx.compose.material3.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:81)
                  	    at androidx.compose.material3.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:80)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
                  	    at androidx.compose.material3.MaterialThemeKt.MaterialTheme(MaterialTheme.kt:73)
                  	    at io.github.sgpublic.kotlinloggingtest.android.MyApplicationThemeKt.MyApplicationTheme(MyApplicationTheme.kt:49)
                  	    at io.github.sgpublic.kotlinloggingtest.android.ComposableSingletons$MainActivityKt$lambda-3$1.invoke(MainActivity.kt:17)
                  	    at io.github.sgpublic.kotlinloggingtest.android.ComposableSingletons$MainActivityKt$lambda-3$1.invoke(MainActivity.kt:16)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:428)
                  	    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:252)
                  	    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:251)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
                  	    at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:195)
                  	    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:119)
     18:44:24.922  E  	at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:118)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
                  	    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:110)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:158)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:157)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:157)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:142)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
                  	    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
                  	    at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
                  	    at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3340)
                  	    at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3273)
                  	    at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:588)
                  	    at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:1013)
                  	    at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:520)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:142)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
                  	    at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1191)
                  	    at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:133)
                  	    at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:183)
                  	    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
                  	    at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.kt:192)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
                  	    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
                  	    at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1266)
                  	    at android.view.View.dispatchAttachedToWindow(View.java:22327)
                  	    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3544)
                  	    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3551)
                  	    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3551)
                  	    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3551)
                  	    at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3551)
                  	    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3492)
                  	    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2917)
                  	    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10163)
                  	    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1634)
                  	    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1643)
                  	    at android.view.Choreographer.doCallbacks(Choreographer.java:1176)
                  	    at android.view.Choreographer.doFrame(Choreographer.java:1080)
                  	    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1609)
                  	    at android.os.Handler.handleCallback(Handler.java:958)
     18:44:24.922  E  	at android.os.Handler.dispatchMessage(Handler.java:99)
                  	    at android.os.Looper.loopOnce(Looper.java:224)
                  	    at android.os.Looper.loop(Looper.java:318)
                  	    at android.app.ActivityThread.main(ActivityThread.java:8711)
                  	    at java.lang.reflect.Method.invoke(Native Method)
                  	    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:561)
                  	    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
                      Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
                  	    ... 91 more
     18:44:24.923  D  Shutting down VM
    

Other information:

  • Android Studio: 2023.1.1 Patch 2 / 2024.1.1
  • kotlin: 1.9.20 / 2.0.0
  • gradle: 8.2 / 8.8
Copy link

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

@sgpublic
Copy link
Author

Sorry for the bothering, I missed the "slf4j-api".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant