Why am I getting this error when I add the Google Translate client library to my Android project?

I am trying to add the Google Translate client library to my Android project for these instructions , which says that I am adding this line to my dependencies in the build.gradle of my library project (which depends on my application project):

compile group: 'com.google.cloud', name: 'google-cloud-translate', version: '0.4.0' 

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

It seems unlikely that Google will post an API with internal inconsistencies. The problem may be specific to my environment. My application consists of a library module that contains most of my code. This is a dependency on the application module. I suspect this has something to do with this.

I use: Gradle 2.14.1; Android Studio 2.2.2; Create tools 25.0.0.

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

Thanks in advance...

+8
android android-gradle google-translate
source share
3 answers

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 check out this documentation: https://cloud.google.com/translate/v2/translating-text-with-rest

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

Hope this helps you otherwise you can knock me down for help.

+3
source share

This seems to be a bug at the end of Google: https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1361

I will leave the bounty open if anyone wants to suggest a workaround.

+3
source share

Can you give the following try, paste 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 additional files that are duplicated in library projects and your own. When it's time to give credit, merge all of the above onto your own html page (or text file) for presentation.

+1
source share

All Articles