2

I have a Java library which gets packaged in a JAR and gets put inside an Android Library. The Android Library then gets packaged as an AAR and gets put inside an Android app.

When trying to launch the Android app, I get the following error:

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;

SLF4J is a dependency within the Java Library. This shows us that the Android AAR didn't bring along the dependencies from the Java library (I learnt this is the case by Googling the issue).

So - I then decided that if the dependencies aren't brought along, I'll add the Java Library and the Android Library to the Android app.

When I now run the Android app, I get the following error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/.../AuthenticationOptions$1.class

Either way doesn't work.

Android app Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "my.application.id"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}

dependencies {
    compile(name:'android-library', ext:'aar')
    compile files('libs/java-library.jar')
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:support-v4:24.1.1'
    compile group: 'org.apache.httpcomponents', name: 'httpclient-android', version: '4.3.5.1'
    compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
    testCompile 'junit:junit:4.12'
}
Subby
  • 5,370
  • 15
  • 70
  • 125
  • If you're any 3rd party library contains SLF4J then you don't need to add externally in build.gradle – M D Sep 29 '16 at 10:02
  • I don't know what you mean. Please elaborate. – Subby Sep 29 '16 at 10:05
  • Where is your build.gradle ? post it – M D Sep 29 '16 at 10:08
  • @MD I've added the `Android app`'s Gradle file. – Subby Sep 29 '16 at 10:12
  • This may help you about adding JAR in android studio app http://stackoverflow.com/questions/16608135/android-studio-add-jar-as-library – VVB Sep 29 '16 at 10:37
  • 1
    @MD Following the tutorial works, however, when I get the `Android Library` which now has the `Java Library` added as a `JAR` Project, it fails to copy over the dependencies... – Subby Sep 29 '16 at 13:20

0 Answers0