我试图优化我的Android应用程序,以目标API 33或API 34为此,我不得不更新protobuf和grpc的库和依赖项。我看到protobuf的javalite版本现在包含在主库中,并且lite版本的使用发生了变化。所以我改变了我的构建。gradle相应。但是我得到以下错误,指示一个类是重复的(有不同的版本?)Type com.google.protobuf.Any$1 is defined multiple times: C:\Users\jenny\.gradle\caches\transforms-3\f587bdbbf1ee885f5ee14d4cd9b8bf8b\transformed\jetified-protobuf-javalite-3.22.3.jar:com/google/protobuf/Any$1.class, C:\Development\workspace\android_studio\VectorCTRLPRO\app\build\intermediates\javac\release\classes\com\google\protobuf\Any$1.class
我对我的build.gradle做了一些修改,以排除一些java和/或javalite版本的protobuf,但我一直得到错误。我还尝试了在无效缓存后进行构建。
正如您将在我的build.gradle(下面)中看到的,我实际上使用的是'com.google.protobuf:protoc:3.23.2',但错误提到了版本3.22.3
所以,如果我能找到什么库使用3. 22. 3,我就可以排除它(也许?)并摆脱这个问题。我怎么才能找到它?
我的构建。gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.jenny.test.app"
minSdkVersion 20
targetSdkVersion 33
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
lintOptions {
disable 'GoogleAppIndexingWarning', 'HardcodedText', 'InvalidPackage'
textReport true
textOutput "stdout"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
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'
exclude 'META-INF/io.netty.versions.properties'
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.7.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.8.0'
implementation 'io.grpc:grpc-okhttp:1.56.1'
implementation ('io.grpc:grpc-protobuf-lite:1.56.1') {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
implementation 'io.grpc:grpc-stub:1.56.1'
implementation 'javax.annotation:javax.annotation-api:1.2'
protobuf ('com.google.protobuf:protobuf-java:3.23.2') {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.protobuf', module: 'protobuf-javalite'
}
protobuf 'com.google.api.grpc:googleapis-common-protos:0.0.3'
implementation 'com.google.android.gms:play-services-ads:22.2.0'
implementation 'org.jcodec:jcodec:0.2.5'
implementation 'org.jcodec:jcodec-android:0.2.5'
implementation 'org.jcodec:jcodec-javase:0.2.5'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation 'com.google.android.ads.consent:consent-library:1.0.8'
implementation 'com.google.android.play:core:1.10.3'
implementation 'com.google.guava:guava:28.2-android'
implementation project(path: ':nativetemplates')
constraints {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
}
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
}
}
}
configurations.implementation {
exclude group: 'com.google.guava', module: 'listenablefuture'
}
protobuf {
protoc { artifact = 'com.google.protobuf:protoc:3.23.2' }
plugins {
grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.56.1' }
}
generateProtoTasks {
all().each { task ->
task.builtins{
java { option 'lite' }
}
task.plugins {
grpc { option 'lite' }
}
}
}
}
1条答案
按热度按时间wgx48brx1#
我也遇到过类似的问题。
来自Github的@ejona86在这里帮助我解决了这个问题:https://github.com/google/protobuf-gradle-plugin/issues/731
原来问题出在旧的“googleapis-common-protos:0.0.3”工件上。我已经更新到2.23.0版本了,但仍然有问题。
然后我被建议手动注入descriptor.proto doing; 1.
1.将文件添加到源:app/src/main/proto/google/protobuf/descriptor.proto
经过这些改变,我的问题消失了。感谢@ejona86