Why do I get this error when I add the Google Translate client library to my Android project?
Asked Answered
H

3

8

I'm trying to add the Google Translate client library to my Android project per these instructions, which tells me to add this line to my dependencies in build.gradle 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'

But when I do, 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 understand what the error means technically but not why it appears in this case. I tried to suppress it by adding a packagingOptions block to my build.gradle per this answer (and others), but it didn't help (plus it's illegal).

It seems unlikely that Google would publish an API with internal inconsistencies. The problem may be specific to my environment. My app consists of a library module that contains most of my code. It's a dependency of the app module. I suspect that has something to do with it.

I'm using: Gradle 2.14.1; Android Studio 2.2.2; Build tools 25.0.0.

Have you successfully added the Google Translate client library to your Android project? If so, how?

Thanks in advance...

Hewie answered 29/10, 2016 at 21:30 Comment(5)
have you tried to clean project, clear cache, and rebuild ?Eggbeater
I did a clean build from AS and I ran gradlew clean. I also blew away ~/.gradle.Hewie
2 points, first i think the isue is because 2 lib are by google, and thus license is duplicate issue somehow? 2nd in this answer #20828385 it talks about Putting the dependecies at the top and the packageOptions at the end, not sure though, it worth a try?Eggbeater
It may be a bug in Android Studio or Gradle: github.com/GoogleCloudPlatform/google-cloud-java/issues/1319Hewie
Yep it's a bug: github.com/GoogleCloudPlatform/google-cloud-java/issues/1361Hewie
D
3

Add the following to your pom.xml file:

<project>
  <dependencies>
    <dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-translate</artifactId>
      <version>v2-rev47-1.22.0</version>
    </dependency>
  </dependencies>
</project>

Add the following to your build.gradle file:

repositories {

    mavenCentral()

}

dependencies {

    compile 'com.google.apis:google-api-services-translate:v2-rev47-1.22.0'

}

And checkout this documentation : https://cloud.google.com/translate/v2/translating-text-with-rest

and in github: https://github.com/google/google-api-java-client

Hope it will be help you otherwise you can knock me for furthe help.

Daguerreotype answered 5/11, 2016 at 11:14 Comment(3)
I don't have a pom.xml file.Hewie
please check this link : github.com/google/google-api-java-clientDaguerreotype
@BarryFruitman do you get warnings/errors when you build with this solution? I get BULD SUCCESSFUL: but their is 8 warnings/336 errors lol. Nice job GoogleFecit
H
3

This appears to be a bug on Google's end: https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1361

I'll leave the bounty open in case someone wants to offer a workaround.

Hewie answered 1/11, 2016 at 21:45 Comment(0)
D
3

Add the following to your pom.xml file:

<project>
  <dependencies>
    <dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-translate</artifactId>
      <version>v2-rev47-1.22.0</version>
    </dependency>
  </dependencies>
</project>

Add the following to your build.gradle file:

repositories {

    mavenCentral()

}

dependencies {

    compile 'com.google.apis:google-api-services-translate:v2-rev47-1.22.0'

}

And checkout this documentation : https://cloud.google.com/translate/v2/translating-text-with-rest

and in github: https://github.com/google/google-api-java-client

Hope it will be help you otherwise you can knock me for furthe help.

Daguerreotype answered 5/11, 2016 at 11:14 Comment(3)
I don't have a pom.xml file.Hewie
please check this link : github.com/google/google-api-java-clientDaguerreotype
@BarryFruitman do you get warnings/errors when you build with this solution? I get BULD SUCCESSFUL: but their is 8 warnings/336 errors lol. Nice job GoogleFecit
R
1

Can you give the following a try, insert in your android block:

packagingOptions {
    exclude 'LICENSE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/DEPENDENCIES.txt'

    // `return void` removes the lint error: `Not all execution paths return a value`.
    return void
}

Add any additional files that are duplicated across library projects and your own. When it comes time to give credit, merge all of the above into their own html page (or a text file) for presentation.

Roderick answered 4/11, 2016 at 17:40 Comment(1)
I already described this solution in my original post. It didn't work then either.Hewie

© 2022 - 2024 — McMap. All rights reserved.