We help IT Professionals succeed at work.
Get Started

NoClassDefFoundError org/slf4j/LoggerFactory;

Rohit Bajaj
Rohit Bajaj asked
on
2,424 Views
Last Modified: 2015-07-21
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
Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE