Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency conflict when adding google-cloud-translate to Android app. #1361

Closed
BarryFruitman opened this issue Nov 1, 2016 · 22 comments
Closed
Assignees

Comments

@BarryFruitman
Copy link

BarryFruitman commented Nov 1, 2016

This 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!

@mziccard
Copy link
Contributor

mziccard commented 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
Copy link
Author

BarryFruitman commented 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
Copy link
Contributor

mziccard commented 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
Copy link
Author

@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
Copy link
Contributor

mziccard commented 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
Copy link
Author

@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
Copy link
Author

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
Copy link
Contributor

mziccard commented Nov 1, 2016

and I got yet another exception

Care to share? :)

@BarryFruitman
Copy link
Author

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
Copy link
Contributor

mziccard commented Nov 3, 2016

@BarryFruitman In case you are still interested this example shows a working Android app using google-cloud-translate 0.5.0.

@BarryFruitman
Copy link
Author

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
Copy link
Contributor

mziccard commented 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):

  • Enable multidex:
    defaultConfig {
        ...
        multiDexEnabled true
    }
  • Force findbugs resolution strategy:
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
  • Exclude duplicate files:
    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.

@BarryFruitman
Copy link
Author

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
Copy link

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

`

@lvs-coding
Copy link

lvs-coding commented Dec 14, 2016

Just for you to know that i had the same problem and the solution provided by mziccard fixed it. At least the app work. I'm getting a bunch of warning and error from Gradle but miraculously the build is finally successful.... I guess it's not the "cleanest" solution but i guess it's the only one too.Thank you mziccard, it was helpful.

Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20151123 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20151123 is ignored for debug as it may be conflicting with the internal version provided by Android.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.google.inject.internal.cglib.core.$AbstractClassGenerator$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.google.inject.internal.cglib.core.$ClassEmitter$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.google.inject.internal.cglib.core.$ClassEmitter$3) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.google.inject.internal.cglib.core.$ClassNameReader$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
etc.......

Error:indicate that it is not an inner class.
Information:BUILD SUCCESSFUL

@grantespo
Copy link

grantespo commented Jan 20, 2017

@mzicard's It builds for me but that 8 warnings and 336 errors are ugly. But when The app actually runs, it force closes with a manifest error. The docs definitely need to be updated. Whoever is in charge of them didn't do a very good job

@gitCopyPaster
Copy link

gitCopyPaster commented Mar 10, 2017

Thanks for sharing the project @mziccard. I was about to give up on android + GCP Translate because of a java.lang.NoClassDefFoundError: com.google.api.services.translate.Translate$Builder error but @mziccard's app compiles and runs for me. I initially saw the 336 errors that @lvs-coding and @grantespo mention (the number of which are inflated because the same, multi-line error is repeated many times.) I was able to suppress them by following this tip and making the simple addition to android-google-cloud-translate-master\app\proguard-rules.pro

@asifrpatel
Copy link

asifrpatel commented Mar 30, 2017

I get the run time exception of java.lang.ClassNotFoundException. class is defined in manifest file.

@gitCopyPaster
Copy link

Which class do you get the exception for? Try comparing your code to @mziccard's working example from earlier in the thread, particularly his build.gradle. For me, adding the line:
compile ('com.google.apis:google-api-services-translate:v2-rev47-1.22.0')
suppressed the class-not-found exception for the Translate$Builder class.

@asifrpatel
Copy link

@gitCopyPaster thanks, your suggestion is helpful.

@vladimirarevshatyan
Copy link

issue still exists and it is 2017...

@gitCopyPaster
Copy link

If you are expecting the issue to be fixed at some point, I wouldn't hold your breath. Please try cloning @mziccard's example from his post in November 2016 and verifying that there is an issue that still exists.

github-actions bot pushed a commit to suztomo/google-cloud-java that referenced this issue Jun 29, 2022
* chore: update github actions

* chore: update
Source-Link: googleapis/synthtool@1622741
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:e3746f84955528d0fe24bf2e4df89875d6ce5a036af01b9c326d61a38838523a
suztomo pushed a commit that referenced this issue Feb 1, 2023
* chore: update github actions

* chore: update
Source-Link: googleapis/synthtool@1622741
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:e3746f84955528d0fe24bf2e4df89875d6ce5a036af01b9c326d61a38838523a
suztomo pushed a commit that referenced this issue Feb 1, 2023
* chore: update github actions

* chore: update
Source-Link: googleapis/synthtool@1622741
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:e3746f84955528d0fe24bf2e4df89875d6ce5a036af01b9c326d61a38838523a
suztomo pushed a commit that referenced this issue Feb 1, 2023
* chore: update github actions

* chore: update
Source-Link: googleapis/synthtool@1622741
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:e3746f84955528d0fe24bf2e4df89875d6ce5a036af01b9c326d61a38838523a

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants