GeezerVison is showing github.com — Dependency conflict when adding google-cloud-translate to Android app. · Issue #1361 · googleapis/google-cloud-java
Dependency conflict when adding google-cloud-translate to Android app. #1361DescriptionThis is essentially a dupe of issue #1319 but with Google Translate.
I added the Google Translate Java client library to my Android app per these instructions, which consists of adding this line to my build.gradle file of my library project (which is a dependency of my app project):
compile group: 'com.google.cloud', name: 'google-cloud-translate', version: '0.4.0'
However when I build, I get this error:
Error:Execution failed for task ':typeSmart:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\com.google.auto.value\auto-value\1.1\f6951c141ea3e89c0f8b01da16834880a1ebf162\auto-value-1.1.jar
File2: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\org.codehaus.jackson\jackson-core-asl\1.9.11\e32303ef8bd18a5c9272780d49b81c95e05ddf43\jackson-core-asl-1.9.11.jar
File3: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\com.google.inject\guice\4.0\f990a43d3725781b6db7cd0acf0a8b62dfd1649\guice-4.0.jar
I tried all the suggestions in the other issue but I'm happy to go over them again.
I'm using the latest version of Android Studio (2.2.2) with the Gradle wrapper.
Any help is much appreciated. Thanks in advance! Activitymziccard commented on Nov 1, 2016 Hi @BarryFruitman, please notice that we do not explicitly support Android, hence the issues you are getting. Let me try to help you though.
Have you tried to get rid of duplications by doing:
packagingOptions {
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/io.netty.versions.properties'
pickFirst 'META-INF/INDEX.LIST'
}
If yes, what happens? BarryFruitman commented on Nov 1, 2016 @mziccard Thanks for your prompt reply. I get the exact same exception. :(
(For the record, where am I supposed to add packagingOptions? The only places I could were inside the android and defaultConfig blocks of the module build.gradle file. Neither had any effect.) mziccard commented on Nov 1, 2016 packagingOptions should go inside the android block in your build.gradle.
I get the exact same exception. :(
This is very strange. Have you done a clean build? Are you still getting a duplicate complaint for META-INF/LICENSE or for a different file?
Let's try something more aggressive:
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
}BarryFruitman commented on Nov 1, 2016 @mziccard Yes I've done many clean builds. I've blown away ~/.gradle too. I've also already tried many variations of the packagingOptions solution that I found on Stack Overflow. :(
Is it possible to statically link the library? Do you have any other suggestions? mziccard commented on Nov 1, 2016 @BarryFruitman you did not answer to my question: "Are you still getting a duplicate complaint for META-INF/LICENSE or for a different file?"
There must be something wrong with your build file. I have been able to reproduce your issue and work around it using excludes. I suggest you do a thorough check of your build file.
Alternatively, you can use the translate API referenced here. BarryFruitman commented on Nov 1, 2016 @mziccard Same file. Sorry that's what I meant when I said exact same exception. :)
Error:Execution failed for task ':typeSmart:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\com.google.auto.value\auto-value\1.1\f6951c141ea3e89c0f8b01da16834880a1ebf162\auto-value-1.1.jar
File2: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\org.codehaus.jackson\jackson-core-asl\1.9.11\e32303ef8bd18a5c9272780d49b81c95e05ddf43\jackson-core-asl-1.9.11.jar
File3: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\com.google.inject\guice\4.0\f990a43d3725781b6db7cd0acf0a8b62dfd1649\guice-4.0.jar
BarryFruitman commented on Nov 1, 2016 I just created a brand new Android project and added the Google Translate library and the packagingOptions fix and I got yet another exception. That's the third one so far from adding Google Cloud libs, and they all happen in transformResourcesWithMergeJavaResForDebug.
I'm just gonna wait until the libs are ready for Prime Time. ;)
Thanks for your help! mziccard commented on Nov 1, 2016
and I got yet another exception
Care to share? :) BarryFruitman commented on Nov 1, 2016 I'm really sorry but I already deleted the project.
Please consider updating the docs to point out the Android incompatibility. It would have saved me a lot of time. mziccard commented on Nov 3, 2016 BarryFruitman commented on Nov 3, 2016 Thanks for following up. I can build and deploy your example project. However I still cannot build my own project. I added the two compile dependencies and packagingOptions to my build.gradle. Here are my dependencies:
dependencies {
compile 'com.android.support:support-compat:25.0.0'
compile files('libs/voiceimeutils.jar')
compile ('com.google.apis:google-api-services-translate:v2-rev47-1.22.0') {
exclude group: 'com.google.guava'
}
compile ('com.google.cloud:google-cloud-translate:0.5.0') {
exclude group: 'io.grpc', module: 'grpc-all'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
}
}
It fixed one of the duplicates. Now I only get two of the three original conflicts:
Error:Execution failed for task ':typeSmart:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
File1: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\com.google.inject\guice\4.0\f990a43d3725781b6db7cd0acf0a8b62dfd1649\guice-4.0.jar
File2: C:\Users\Barry\.gradle\caches\modules-2\files-2.1\org.codehaus.jackson\jackson-core-asl\1.9.11\e32303ef8bd18a5c9272780d49b81c95e05ddf43\jackson-core-asl-1.9.11.jar
At least it's progress! Should I have copied anything else from your example project? mziccard commented on Nov 3, 2016 @BarryFruitman the relevant bits from the example are the following (see the example's build.gradle to see where to put them):
defaultConfig {
...
multiDexEnabled true
}
- Force findbugs resolution strategy:
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
}
- Import google-cloud-translate avoiding duplicates:
compile ('com.google.apis:google-api-services-translate:v2-rev47-1.22.0') {
exclude group: 'com.google.guava'
}
compile ('com.google.cloud:google-cloud-translate:0.5.0') {
exclude group: 'io.grpc', module: 'grpc-all'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
}
If this is in place you should not have problems running your app. Please double check and do a clean build. Reacted by Nabin Khatiwada BarryFruitman commented on Nov 4, 2016 I still get the same exception. I tried a clean build in both the IDE and command line. I even blew away ~/.gradle.
The silver lining is now the command line reports the same error as the IDE. :-P Osoter commented on Nov 22, 2016 I've the same problem of Barry.
`apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion 24.0.1
defaultConfig {
applicationId "com.blabla.app"
minSdkVersion 22
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile 'com.google.apis:google-api-services-storage:+'
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.apis:google-api-services-vision:v1-rev30-1.22.0'
compile ('com.google.cloud:google-cloud-translate:0.6.0'){
exclude group: 'io.grpc', module: 'grpc-all'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
}
}
repositories{
mavenCentral()
}
dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}
`
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|