android protobuf javalite 和 R8
android protobuf javalite and R8
我的 release 构建任务失败:minifyReleaseWithR8
> Task :app:minifyReleaseWithR8 FAILED
AGPBI: {"kind":"error","text":"Type com.google.protobuf.SourceContextOrBuilder is defined multiple times: /Users/userz/.gradle/caches/transforms-2/files-2.1/fa3559cc4d07efe76175d461f7267b38/jetified-protobuf-javalite-3.11.0.jar:com/google/protobuf/SourceContextOrBuilder.class, /Users/userz/path-to-project/build/intermediates/javac/release/classes/com/google/protobuf/SourceContextOrBuilder.class","sources":[{"file":"/Users/userz/.gradle/caches/transforms-2/files-2.1/fa3559cc4d07efe76175d461f7267b38/jetified-protobuf-javalite-3.11.0.jar"}],"tool":"R8"}
项目中的protobuf定义如下:
protobuf {
protoc {
// You still need protoc like in the non-Android case
artifact = "com.google.protobuf:protoc:3.11.0"
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option "lite"
}
}
}
}
}
protobuf "com.google.protobuf:protobuf-javalite:3.11.0"
有趣的是,如果我删除 firebase 性能库
implementation "com.google.firebase:firebase-perf"
比构建失败更早(在 :kaptReleaseKotlin 任务上)
> Task :app:kaptReleaseKotlin
path-to-project/build/generated/source/proto/release/java/main/MessageOuterClass.java:9: error: cannot find symbol
com.google.protobuf.ExtensionRegistryLite registry) {
symbol: class ExtensionRegistryLite
location: package com.google.protobuf/path-to-project/build/generated/source/proto/release/java/main/MessageOuterClass.java:493: error: cannot find symbol
com.google.protobuf.MessageLiteOrBuilder {
implementation "com.google.protobuf:protobuf-javalite:3.11.0"
解决了问题
我的 release 构建任务失败:minifyReleaseWithR8
> Task :app:minifyReleaseWithR8 FAILED
AGPBI: {"kind":"error","text":"Type com.google.protobuf.SourceContextOrBuilder is defined multiple times: /Users/userz/.gradle/caches/transforms-2/files-2.1/fa3559cc4d07efe76175d461f7267b38/jetified-protobuf-javalite-3.11.0.jar:com/google/protobuf/SourceContextOrBuilder.class, /Users/userz/path-to-project/build/intermediates/javac/release/classes/com/google/protobuf/SourceContextOrBuilder.class","sources":[{"file":"/Users/userz/.gradle/caches/transforms-2/files-2.1/fa3559cc4d07efe76175d461f7267b38/jetified-protobuf-javalite-3.11.0.jar"}],"tool":"R8"}
项目中的protobuf定义如下:
protobuf {
protoc {
// You still need protoc like in the non-Android case
artifact = "com.google.protobuf:protoc:3.11.0"
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option "lite"
}
}
}
}
}
protobuf "com.google.protobuf:protobuf-javalite:3.11.0"
有趣的是,如果我删除 firebase 性能库
implementation "com.google.firebase:firebase-perf"
比构建失败更早(在 :kaptReleaseKotlin 任务上)
> Task :app:kaptReleaseKotlin
path-to-project/build/generated/source/proto/release/java/main/MessageOuterClass.java:9: error: cannot find symbol
com.google.protobuf.ExtensionRegistryLite registry) {
symbol: class ExtensionRegistryLite
location: package com.google.protobuf/path-to-project/build/generated/source/proto/release/java/main/MessageOuterClass.java:493: error: cannot find symbol
com.google.protobuf.MessageLiteOrBuilder {
implementation "com.google.protobuf:protobuf-javalite:3.11.0"
解决了问题