在导入几个外部jar包至AS中lib文件夹,并add as library后,build.gradle文件中生成:
dependencies {
// lib编译jar包
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile('io.socket:socket.io-client:0.7.0') {
exclude group: 'org.json', module: 'json'
}
compile 'com.google.android.gms:play-services:8.4.0'
compile project(':library')
compile files('src/main/libs/universal-image-loader-1.9.4.jar')
compile files('src/main/libs/json-lib-2.4-jdk15.jar')
compile files('src/main/libs/commons-collections-3.2.2.jar')
compile files('src/main/libs/ezmorph-1.0.6.jar')
compile files('src/main/libs/commons-beanutils-1.7.0.jar')
compile files('src/main/libs/commons-lang-2.5.jar')
compile files('src/main/libs/commons-logging.jar')
}
编译报错如标题。
My understanding is that there are duplicate references to the same API (Likely different version numbers). It should be reasonably easy to debug when building from the command line.
Try ./gradlew yourBuildVariantName –debug from the command line.
The offending item will be the first failure. An example might look like:
14:32:29.171 [INFO] [org.gradle.api.Task] INPUT: /Users/mydir/Documents/androidApp/BaseApp/build/intermediates/exploded-aar/theOffendingAAR/libs/google-play-services.jar
14:32:29.171 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ‘:BaseApp:packageAllyourBuildVariantNameClassesForMultiDex’
14:32:29.172 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :BaseApp:packageAllyourBuildVariantNameClassesForMultiDex FAILED’
In the case above, the aar file that I’d included in my libs directory (theOffendingAAR) included the Google Play Services jar (yes the whole thing. yes I know.) file whilst my BaseApp build file utilised location services:
compile 'com.google.android.gms:play-services-location:6.5.87'
You can safely remove the offending item from your build file(s), clean and rebuild (repeat if necessary).
简单说就是移除compile ‘com.google.android.gms:play-services-location:xxx’来解决。