构建我的android项目时出现以下错误:
已存在的程序类型: com.google.common.annotations.GwtCompatible消息{kind = ERROR, text =已存在的程序类型: com.google.common.annotations.GwtCompatible,sources = [未知来源 文件],工具名称= Optional.of(D8)}
gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.www.www"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// multi-dex support (When your app and the libraries it references exceed 65,536 methods)
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/INDEX.LIST'
}
}
dependencies {
// multi-dex support (When your app and the libraries it references exceed 65,536 methods)
implementation 'com.android.support:multidex:1.0.3'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//this is for the google "text recognizer"
implementation 'com.google.android.gms:play-services-vision:15.0.2'
implementation 'com.google.apis:google-api-services-customsearch:v1-rev63-1.23.0'
//for firebase database connection
implementation 'com.google.firebase:firebase-database:16.0.1'
//implementation 'com.google.firebase:firebase-core:16.0.0'
// for firebase authentication
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.android.gms:play-services-auth:15.0.1'
// for Google Natural Language Processing (part of google cloud services)
implementation ('com.google.cloud:google-cloud-language:1.31.0')
// {
// exclude group: 'com.google.guava'
// }
}
apply plugin: 'com.google.gms.google-services'
以下解决了这个问题:
implementation ('com.google.cloud:google-cloud-language:1.31.0') {
exclude group: 'com.google.guava'
}
但是我失去了guava函数,因为在运行时会抛出以下错误:
未找到“com.google.common.base.MoreObjects”类
引起:java.lang.NoClassDefFoundError:解析失败: LCOM /谷歌/普通/碱/ MoreObjects;
当我运行以下代码时: public void testSomething(查看视图){
// Instantiate the Language client com.google.cloud.language.v1.LanguageServiceClient
try {
InputStream inputStream = getAssets().open("www.json");
GoogleCredentials googleCredential = GoogleCredentials.fromStream(inputStream);
}
catch (Exception e){
Log.e(TAG,e.getMessage());
e.printStackTrace();
}
我在这里转圈。我迫不及待地想找到答案。 我已经检查了其他问题/主题,没有答案可以帮助我。
答案 0 :(得分:0)
我通过以下更改解决了相同的问题:
implementation ('com.google.apis:google-api-services-drive:v2-rev105-1.17.0-rc'){
exclude module: 'guava-jdk5'
}
implementation ('com.google.api-client:google-api-client-android:1.20.0'){
exclude module: 'guava-jdk5'
}
答案 1 :(得分:-1)
更改等级为:
implementation 'com.google.apis:google-api-services-vision:v1-rev369-1.23.0' exclude module: 'guava-jdk5'
implementation 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'guava-jdk5' exclude module: 'httpclient'
implementation 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
这对我有用