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'
}