android - Android Gradle Protobufs:如何编译完整的 protobuf 而不是“lite”版本?
问题描述
我能找到的配置build.gradle以编译 protobufs 的每个示例都使用“lite”版本,看起来像这样:
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.6.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite { }
}
}
}
}
dependencies {
implementation 'com.google.protobuf:protobuf-java:3.6.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}
注意“ javalite ”。这会生成使用MessageLite的 java 文件,但我需要完整的Message类。
如何更改它以使其不生成“精简版”版本?
解决方案
找到了解决方案:
1)删除这个:
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
2)删除这个:
task.plugins {
javalite { }
}
3)将 task.builtins 部分更改为:
task.builtins {
java { }
}
它现在将生成功能齐全的 protobuffs。
推荐阅读
- linux - Linux 上的 Xamarin GTK:“DllNotFoundException:libglib-2.0-0.dll”
- performance - 提高 Fortran 计算时间
- python - 使用 python 获取某个文件后,如何从谷歌云存储桶中获取文件?
- database - Mongodb 16 MB 文档示例,实际数据量是多少?
- terraform - Terraform - 模板中具有可选成员的动态云配置组
- json - Googla Analytics 4 - 商务跟踪不起作用
- javascript - 使用Javascript根据子编号添加CSS类(HTML)
- http - 正在处理的项目的 HTTP 状态代码
- javascript - auth0.js 无法获取刷新令牌
- javascript - React js:不使用引用(Ref),从父级访问子状态