protobuf on android
Introduction
Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
This article is about how to setup protobuf on android.
Android app settings
Following settings is not mandatory, it’s just the pre-settings of the sample app.
language: Kotlin
Steps
Add plugin for gradle
The latest version is 0.8.12. It requires at least Gradle 5.6 and Java 8. It is available on Maven Central. To add dependency to it in the build.gradle of root:
Add plugin to your project
Customizing source directories
-
Create directory app/src/main/proto.
-
Put *.proto files to app/src/main/proto.
Add dependency
Add dependency to app build.gradle and configure protobuf tasks.
Everything’s ok, clean project and build. you can use the generated class.