我正在尝试使用Google的Cloud Translation API制作谷歌翻译应用程序。我正在尝试编译编译'com.google.cloud:google-cloud-translate:1.14.0'错误,因为在APK project.properties中复制了重复文件
我的android代码如下(在java代码中没问题)
import com.google.cloud.translate.Translate;
import com.google.cloud.translate.Translate.TranslateOption;
import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation;
public class QuickstartSample {
public static void main(String... args) throws Exception {
Translate translate = TranslateOptions.getDefaultInstance().getService();
String text = "Hello, world!";
Translation translation =
translate.translate(
text,
TranslateOption.sourceLanguage("en"),
TranslateOption.targetLanguage("ru"));
System.out.printf("Text: %s%n", text);
System.out.printf("Translation: %s%n", translation.getTranslatedText());
}
}
我的build.gradle如下所示(问题由于下面的编译语句而引起)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.googletranslation"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
**compile 'com.google.cloud:google-cloud-translate:1.14.0'**
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
testCompile 'junit:junit:4.12'
}
我得到的错误如下:
错误:与项目':app'中的依赖项'com.google.code.findbugs:jsr305'冲突。 app(3.0.0)和测试app(2.0.1)的已解决版本有所不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict。
警告:警告:依赖org.apache.httpcomponents:httpclient:4.0.1因发布而被忽略,因为它可能与Android提供的内部版本冲突。 如有问题,请使用jarjar重新包装以更改类包
警告:警告:依赖org.json:json:20160810因发布而被忽略,因为它可能与Android提供的内部版本冲突。 如有问题,请使用jarjar重新包装以更改类包
我已尝试过以下链接中的所有方法,但没有效果。仍有错误正在增加
Error:Conflict with dependency 'com.google.code.findbugs:jsr305'
答案 0 :(得分:0)
必须包含以下内容:
android {
packagingOptions {
exclude 'project.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
defaultConfig {
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}}
}