Created
April 3, 2024 16:14
-
-
Save angelorohit/d302af2f3674d3a083649288d52780df to your computer and use it in GitHub Desktop.
ProtoDataStore integration into an Android project using the Kotlin DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the build.gradle at the root level of the project. | |
plugins { | |
alias(libs.plugins.protobuf) apply false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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