I've been struggling for 4+ days now on Gradle's dependencies in Android Studio.
I'm trying to create a java library (MyLibrary) that requires some external dependencies, namely commons-codec. I added it inside my build.gradle, which looks something like this.
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'commons-codec:commons-codec:1.10'
}
I was able to assemble my debug and release AAR files in Android Studio. Now in my Android project, I added MyLibrary by importing it as an AAR module and setup the build.gradle file for my project to look like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
// useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.my.package"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.android.gms:play-services:7.8.+'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'commons-codec:commons-codec:1.10'
compile project(':MyLibrary')
}
The project build, and the app installed but crashes when it executes the part of the code that uses common-codec.
FATAL EXCEPTION: Thread-172468 java.lang.NoSuchMethodError: No static method encodeHexString([B)Ljava/lang/String; in class Lorg/apache/commons/codec/binary/Hex; or its super classes (declaration of 'org.apache.commons.codec.binary.Hex' appears in /system/framework/ext.jar)
at org.apache.commons.codec.digest.DigestUtils.sha256Hex
My question is, why common-codec isn't included in MyLibrary?
Thanks