我在android实现中使用带有protobuf lite的grpc。但是 protobuf lite 没有 google 时间戳,而我的 protos 导入了“google/protobuf/timestamp.proto”。所以我添加了实现 'com.google.protobuf:protobuf-java:3.7.1' 到包含谷歌时间戳的gradle。但在那之后代码编译有错误。例如 :Duplicate class com.google.protobuf.AbstractMessageLite 在模块 protobuf-java-3.7.1.jar (com.google.protobuf:protobuf-java:3.7.1) 和 protobuf-lite-3.0.1.jar ( com.google.protobuf:protobuf-lite:3.0.1)。任何解决此问题的想法将不胜感激。
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 28
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
proto {
srcDir 'src/main'
}
java {
srcDir 'src/main'
}
} …Run Code Online (Sandbox Code Playgroud)