我正在尝试按照these instructions将Google翻译客户端库添加到我的Android项目中,这告诉我将此行添加到我的库项目的build.gradle中的依赖项(这是我的应用程序项目的依赖项):
compile group: 'com.google.cloud', name: 'google-cloud-translate', version: '0.4.0'
但是当我这样做时,我收到了这个错误:
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
我理解错误在技术上意味着什么,但不是为什么它在这种情况下出现。我试图通过在this answer(和其他人)的build.gradle中添加packagingOptions
块来抑制它,但它没有帮助(加上它是非法的)。
Google似乎不太可能发布内部不一致的API。问题可能与我的环境有关。我的应用程序包含一个包含大部分代码的库模块。它是app模块的依赖项。我怀疑这与它有关。
我正在使用:Gradle 2.14.1; Android Studio 2.2.2;构建工具25.0.0。
您是否已成功将Google翻译客户端库添加到Android项目中?如果是这样,怎么样?
提前致谢...
答案 0 :(得分:3)
这似乎是Google最终的错误:https://github.com/GoogleCloudPlatform/google-cloud-java/issues/1361
如果有人想要提供解决方法,我会保留赏金。
答案 1 :(得分:3)
将以下内容添加到pom.xml
文件中:
<project>
<dependencies>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-translate</artifactId>
<version>v2-rev47-1.22.0</version>
</dependency>
</dependencies>
</project>
将以下内容添加到build.gradle
文件中:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-translate:v2-rev47-1.22.0'
}
并查看此文档:https://cloud.google.com/translate/v2/translating-text-with-rest
并在github中: https://github.com/google/google-api-java-client
希望它能为你提供帮助,否则你可以帮我敲门。
答案 2 :(得分:1)
你可以试试下面的内容,插入你的android块:
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
}
添加跨库项目和您自己的项目重复的任何其他文件。 当需要提供信用时,将上述所有内容合并到他们自己的html页面(或文本文件)中进行演示。