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

minSdkVersion 26
minSdkVersion 29

multiDexEnabled true

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8


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:

buildscript {
    repositories {
    dependencies {
        classpath ''

Add plugin to your project

apply plugin: ''  // or ''
apply plugin: ''

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.

dependencies {
  // You need to depend on the lite runtime library, not protobuf-java
  compile ''

protobuf {
  protoc {
    artifact = ''
  generateProtoTasks {
    all().each { task ->
      task.builtins {
        java {
          option "lite"

Everything’s ok, clean project and build. you can use the generated class.