Skip to content

Instantly share code, notes, and snippets.

@angelorohit
Created April 3, 2024 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelorohit/d302af2f3674d3a083649288d52780df to your computer and use it in GitHub Desktop.
Save angelorohit/d302af2f3674d3a083649288d52780df to your computer and use it in GitHub Desktop.
ProtoDataStore integration into an Android project using the Kotlin DSL
// This is the build.gradle at the app or module level.
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.protobuf)
}
dependencies {
// DataStore
implementation(libs.androidx.datastore)
// Protobuf
implementation(libs.protobuf.java.lite)
implementation(libs.protobuf.kotlin.lite)
}
protobuf {
protoc {
// We get this from TOML file.
artifact = "${libs.protobuf.compiler.get()}"
}
plugins {
generateProtoTasks {
all().forEach {
it.builtins {
// We need to create both Java and Kotlin because Kotlin DSL depends on the JavaLite protobuf.
create("java") {
option("lite")
}
create("kotlin") {
option("lite")
}
}
}
}
}
}
// This is the build.gradle at the root level of the project.
plugins {
alias(libs.plugins.protobuf) apply false
}
[versions]
datastore = "1.0.0"
protobufPlugin = "0.9.4"
protobuf = "4.26.1"
[libraries]
# DataStore
androidx-datastore = { group = "androidx.datastore", name = "datastore", version.ref = "datastore" }
# Protobuf
protobuf-compiler = { group = "com.google.protobuf", name = "protoc", version.ref = "protobuf" }
protobuf-java-lite = { group = "com.google.protobuf", name = "protobuf-javalite", version.ref = "protobuf" }
protobuf-kotlin-lite = { group = "com.google.protobuf", name = "protobuf-kotlin-lite", version.ref = "protobuf" }
[plugins]
protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment