bananana
bananana

Reputation: 105

How to fix: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory

I have an project which includes a libraryproject. My main project has the following dependencies:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile project(':foundationclasses')
    compile 'com.android.support:multidex:'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'

    //NEUROTECHNOLOGY
    compile files('libs/neurotec-media-android.jar')
    compile files('libs/neurotec-media-processing-android.jar')
    compile files('libs/neurotec-licensing-gui-android.jar')
    compile files('libs/neurotec-licensing-android.jar')
    compile files('libs/neurotec-gui-android.jar')
    compile files('libs/neurotec-devices-android.jar')
    compile files('libs/neurotec-core-android.jar')
    compile files('libs/neurotec-cluster-android.jar')
    compile files('libs/neurotec-biometrics-gui-android.jar')
    compile files('libs/neurotec-biometrics-client-android.jar')
    compile files('libs/neurotec-biometrics-android.jar')
    compile files('libs/jna.jar')
    compile files('libs/acra.jar')

    //CREDENCE
    compile files('libs/CredenceDeviceLib.jar')

    //OTHER
    compile 'cn.pedant.sweetalert:library:1.3'
    compile 'com.github.fengdai:alertdialogpro-theme-material:0.2.6'
    compile 'joda-time:joda-time:2.9.3'
    compile 'com.wang.avi:library:1.0.2'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.12'
}

My library project`s dependencies:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.google.guava:guava:18.0'
    compile 'com.github.tony19:logback-android-classic:1.1.1-4'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.12'
}

gradlew app:dependencies gives the following result:

compile - Classpath for compiling the main sources.
+--- project :foundationclasses                                          
|    +--- com.google.guava:guava:18.0
|    +--- com.github.tony19:logback-android-classic:1.1.1-4
|    |    +--- com.github.tony19:apktool-lib:1.4.4-3
|    |    |    \--- com.google.android:android:2.1_r1
|    |    |         +--- commons-logging:commons-logging:1.1.1
|    |    |         +--- org.apache.httpcomponents:httpclient:4.0.1
|    |    |         |    +--- org.apache.httpcomponents:httpcore:4.0.1
|    |    |         |    +--- commons-logging:commons-logging:1.1.1
|    |    |         |    \--- commons-codec:commons-codec:1.3
|    |    |         +--- org.khronos:opengl-api:gl1.1-android-2.1_r1
|    |    |         +--- xerces:xmlParserAPIs:2.6.2
|    |    |         \--- xpp3:xpp3:1.1.4c
|    |    \--- com.github.tony19:logback-android-core:1.1.1-4
|    \--- org.slf4j:slf4j-api:1.7.12
+--- com.android.support:multidex: FAILED
+--- com.android.support:appcompat-v7:23.3.0
|    +--- com.android.support:support-vector-drawable:23.3.0
|    |    \--- com.android.support:support-v4:23.3.0
|    |         \--- com.android.support:support-annotations:23.3.0
|    +--- com.android.support:animated-vector-drawable:23.3.0
|    |    \--- com.android.support:support-vector-drawable:23.3.0 (*)
|    \--- com.android.support:support-v4:23.3.0 (*)
+--- cn.pedant.sweetalert:library:1.3
|    \--- com.pnikosis:materialish-progress:1.0
|         \--- com.android.support:appcompat-v7:21.0.0 -> 23.3.0 (*)
+--- com.github.fengdai:alertdialogpro-theme-material:0.2.6
|    +--- com.nineoldandroids:library:2.4.0
|    \--- com.github.fengdai:alertdialogpro-core:0.2.6
|         \--- com.android.support:appcompat-v7:23.1.1 -> 23.3.0 (*)
+--- joda-time:joda-time:2.9.3   
+--- com.wang.avi:library:1.0.2  
|    +--- com.android.support:appcompat-v7:22.2.0 -> 23.3.0 (*)
|    \--- com.nineoldandroids:library:2.4.0
\--- org.slf4j:slf4j-api:1.7.12  

Error log:

java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at nl.hsb.abis.fsm.ActivityController.<clinit>(ActivityController.java:33)
at nl.hsb.finalapplication.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)   

I have tried everything but i cant get rid of this error, any advice would be greatly appreciated!

Upvotes: 2

Views: 3174

Answers (2)

Ceki
Ceki

Reputation: 27490

The {org.slf4j.LoggerFactory} class ships with slf4j-api.jar. For some mysterious reason slf4j-api.jar is not part of your application at runtime.

Upvotes: 0

Henry
Henry

Reputation: 43788

You included the slf4j API but no implementation. There are several different implementation modules depending on the logger you want to use.

For example, you could add a dependency for the simple logger:

dependencies {
    ...
    runtime group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.12'
    ...
}

Upvotes: 1

Related Questions