在 Android Studio 中使用 Google 翻译 API
Using Google Translation API in Android Studio
我正在尝试制作一个使用 Google 翻译 API 的应用程序。
因为我添加了
compile 'com.google.cloud:google-cloud-translate:1.12.0'
我的 build.gradle 中的依赖项 我有一个错误:
Error:Execution failed for task ':app:javaPreCompileDebug'.
Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.
- auto-value-1.2.jar (com.google.auto.value:auto-value:1.2)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
然后我也添加了
annotationProcessor 'com.google.auto.value:auto-value:1.2'
到 build.gradle 中的依赖项,我得到了这个错误:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'project.properties'
有人可以帮我吗?
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.cloud:google-cloud-translate:1.12.0'
annotationProcessor 'com.google.auto.value:auto-value:1.2'
}
试试这个。
compile('com.google.cloud:google-cloud-translate:1.12.0') {
exclude module: 'httpclient' //by artifact name
exclude group: 'org.apache.httpcomponents' //by group
exclude group: 'com.google.code.findbugs'
exclude group: 'org.json', module: 'json'
}
它解决了我的问题。
编辑
在依赖项{}块之前添加这个
用于解决
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
放
packagingOptions {
exclude 'project.properties'
exclude 'META-INF/INDEX.LIST'
}
进入我的 build.gradle 解决了问题。
我正在尝试制作一个使用 Google 翻译 API 的应用程序。 因为我添加了
compile 'com.google.cloud:google-cloud-translate:1.12.0'
我的 build.gradle 中的依赖项 我有一个错误:
Error:Execution failed for task ':app:javaPreCompileDebug'.
Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration. - auto-value-1.2.jar (com.google.auto.value:auto-value:1.2) Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
然后我也添加了
annotationProcessor 'com.google.auto.value:auto-value:1.2'
到 build.gradle 中的依赖项,我得到了这个错误:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'project.properties'
有人可以帮我吗?
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.cloud:google-cloud-translate:1.12.0'
annotationProcessor 'com.google.auto.value:auto-value:1.2'
}
试试这个。
compile('com.google.cloud:google-cloud-translate:1.12.0') {
exclude module: 'httpclient' //by artifact name
exclude group: 'org.apache.httpcomponents' //by group
exclude group: 'com.google.code.findbugs'
exclude group: 'org.json', module: 'json'
}
它解决了我的问题。
编辑
在依赖项{}块之前添加这个
用于解决
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
放
packagingOptions {
exclude 'project.properties'
exclude 'META-INF/INDEX.LIST'
}
进入我的 build.gradle 解决了问题。