gpt4 book ai didi

android - 解决重复的类依赖性-Gradle

转载 作者:行者123 更新时间:2023-12-03 04:46:12 25 4
gpt4 key购买 nike

我一直在寻找解决方案,但是没有运气。
我在同一项目中添加了Google Cloud Speech API和Google Cloud Translation API。删除任何依赖项都会构建项目,但同时保留所有依赖项则会显示重复的类错误,我不知道如何解决此问题的确切线索。

依存关系:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Support libraries
implementation "com.android.support:design:$supportLibraryVersion"
implementation "com.android.support:cardview-v7:$supportLibraryVersion"
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"

// gRPC
implementation "io.grpc:grpc-okhttp:$grpcVersion"
implementation "io.grpc:grpc-protobuf-lite:$grpcVersion"
implementation "io.grpc:grpc-stub:$grpcVersion"
implementation 'javax.annotation:javax.annotation-api:1.3.2'
protobuf 'com.google.protobuf:protobuf-java:3.8.0'

// OAuth2 for Google API
implementation('com.google.auth:google-auth-library-oauth2-http:0.7.0') {
exclude module: 'httpclient'
}

//Translation
implementation('com.google.cloud:google-cloud-translate:1.12.0') {
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.json', module: 'json'
}
annotationProcessor 'com.google.cloud:google-cloud-translate:1.12.0'

// Tests
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'}

尝试过的
  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 'project.properties'

}

没有任何解决。

错误:
 Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.4.0.jar (com.google.protobuf:protobuf-java:3.4.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-java-3.4.0.jar (com.google.protobuf:protobuf-java:3.4.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)

我应该排除哪些类,并且应该对gradle属性执行什么操作?

最佳答案

我遇到过同样的问题

添加:

排除组:“com.google.protobuf”


 implementation('com.google.cloud:google-cloud-translate:1.12.0') {
exclude group: 'org.apache.httpcomponents'
exclude group: 'org.json', module: 'json'
exclude group: 'com.google.protobuf'

}
annotationProcessor 'com.google.cloud:google-cloud-translate:1.12.0'
}

并确保拥有这些属性对我有用:
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 'project.properties'

}

关于android - 解决重复的类依赖性-Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56956508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com