Link to home
Create AccountLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

NoClassDefFoundError org/slf4j/LoggerFactory;

HI,
Although i am getting this error after including aar in a project but its only java stuff.

I have a project called logging which i wanted to use in another project called Vader. So i made an aar of it.
The build.gradle file for logging is as follows :
apply plugin: 'android-library'
apply plugin: 'maven'

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res', 'res-flags']
            assets.srcDirs = ['assets']
        }
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'com.squareup:tape:1.2.2'
    compile 'com.github.tony19:logback-android-classic:1.1.1-2'
    compile 'to.talk.external:myjson:2.2.4'
}

def coreAarFile = file('build/logging.aar')
artifacts {
    archives coreAarFile
}

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://ci.aws.talk.to:8081/nexus/content/repositories/snapshots",
                       authentication: [
                               userName: 'deployer',
                               password:'qwedsa'
                       ])
            pom.groupId = 'to.talk.aragorn'
            pom.artifactId = 'logging'
            pom.version = '0.5-SNAPSHOT'
        }
    }
}

Open in new window


After running build in gradle it generated an aar file with name : logging-release.aar which i place in the lib folder of my vader project and add the line :
    compile(name: 'logging', ext: 'aar')
in the build.gradle of the project.
Now i am using one of its function in my project. Although the project compiles perfectly but it gives the following error on runtime :

On Running i am getting the following error :
06-22 18:30:36.797  16634-16634/co.riva.vader E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: co.riva.vader, PID: 16634
    java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
            at to.talk.logging.LoggerFactory.<clinit>(LoggerFactory.java:37)
            at to.talk.logging.LoggerFactory.getTrimmer(LoggerFactory.java:71)
            at co.riva.vader.HomeActivity.<clinit>(HomeActivity.java:60)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.Class.newInstance(Class.java:1606)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[zip file "/data/app/co.riva.vader-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at to.talk.logging.LoggerFactory.<clinit>(LoggerFactory.java:37)
            at to.talk.logging.LoggerFactory.getTrimmer(LoggerFactory.java:71)
            at co.riva.vader.HomeActivity.<clinit>(HomeActivity.java:60)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.Class.newInstance(Class.java:1606)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    Suppressed: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
            at java.lang.Class.classForName(Native Method)
            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 18 more

Open in new window


Even though build.gradle inside loggin has the entry for compile 'org.slf4j:slf4j-api:1.7.7'
Still when the aar is included its giving error.
What could be the reason for this. How can i correct it.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Rohit Bajaj

ASKER

I included the following
    compile 'org.slf4j:slf4j-simple:1.7.12'
in build.gradle file
But now i am getting the following error :

06-22 19:54:43.337  26759-26759/co.riva.vader E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: co.riva.vader, PID: 26759
    java.lang.NoClassDefFoundError: Failed resolution of: Lch/qos/logback/classic/Logger;
            at to.talk.logging.LoggerFactory.<clinit>(LoggerFactory.java:37)
            at to.talk.logging.LoggerFactory.getTrimmer(LoggerFactory.java:71)
            at co.riva.vader.HomeActivity.<clinit>(HomeActivity.java:60)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.Class.newInstance(Class.java:1606)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "ch.qos.logback.classic.Logger" on path: DexPathList[[zip file "/data/app/co.riva.vader-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at to.talk.logging.LoggerFactory.<clinit>(LoggerFactory.java:37)
            at to.talk.logging.LoggerFactory.getTrimmer(LoggerFactory.java:71)
            at co.riva.vader.HomeActivity.<clinit>(HomeActivity.java:60)
            at java.lang.reflect.Constructor.newInstance(Native Method)
            at java.lang.Class.newInstance(Class.java:1606)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1066)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2226)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    Suppressed: java.lang.ClassNotFoundException: ch.qos.logback.classic.Logger
            at java.lang.Class.classForName(Native Method)
            at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
            at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 18 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Open in new window


It looks like i need to again add some dependency to resolve this further...
How can i resolve it
You need to read my comment again - more carefully