Mah*_*alv 7 android gradle-kotlin-dsl android-jetpack-datastore
在 jetpack 数据存储中,您必须设置 gradle 插件任务以从.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'
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的项目中,我将Kotlin dsl用于我的 gradle 项目。尝试将其转换为 kotlin dsl 后,option属性未知,我找不到它的替代品 kotlin kts
// 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'
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Mah*_*alv 14
要使用Jetpack proto 数据存储,请为Gradle Kotlin Dsl使用以下代码
// top of file
import com.google.protobuf.gradle.*
plugins {
id("com.google.protobuf") version "0.8.12"
// ...
}
dependencies {
// ...
implementation("com.google.protobuf:protobuf-javalite:3.10.0")
implementation("androidx.datastore:datastore:1.0.0-alpha03")
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
generateProtoTasks {
all().forEach { task ->
task.plugins{
create("java") {
option("lite")
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您也可以使用内置函数。
import com.google.protobuf.gradle.*
generateProtoTasks {
all().forEach { task ->
task.builtins {
id("java") {
option("lite")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
558 次 |
| 最近记录: |