在 jetpack 数据存储中,您必须 set the gradle plugin task用于从 .proto
中生成类文件:
// build.gradle
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
// Generates the java Protobuf-lite code for the Protobufs in this project. See
// https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
// for more information.
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
}
}
}
}
在我的项目中,我使用 Kotlin dsl 对于我的 gradle 项目。尝试将其转换为 kotlin dsl 后,option
属性未知,我找不到它可以替代 kotlin kts// build.gradle.kts
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
java {
option = "lite" // ** option is unknown **
}
}
}
}
}
最佳答案
使用 Jetpack 原型(prototype)数据存储 使用以下代码 Gradle Kotlin DSL
// top of file
import com.google.protobuf.gradle.*
plugins {
id("com.google.protobuf") version "0.8.12"
// ...
}
val protobufVersion = "3.18.0"
dependencies {
// ...
implementation("com.google.protobuf:protobuf-javalite:$protobufVersion")
implementation("androidx.datastore:datastore:1.0.0-alpha03")
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobufVersion"
}
generateProtoTasks {
all().forEach { task ->
task.plugins{
create("java") {
option("lite")
}
}
}
}
}
关于android - Jetpack 原型(prototype)数据存储 - 使用 Kotlin dsl 进行 gradle 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64811006/