combine .proto in android studio project code example

Example 1: combine .proto in android studio project

sourceSets {
        main {
            java {
                srcDir 'src/main/java'
            }
            proto {
                srcDir 'src/main/proto'
            }
        }
    }12345678910

Example 2: combine .proto in android studio project

apply plugin: 'com.google.protobuf'1

Example 3: combine .proto in android studio project

buildscript {    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.2' //The version below 0.8 must be 0.8.0
    }
}12345678910

Example 4: combine .proto in android studio project

protobuf {
    //Configure the protoc compiler
    protoc {
        artifact = 'com.google.protobuf:protoc:3.5.1'
    }
    //Configure the build directory here, after compilation, the corresponding java file will be generated in the build directory
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                remove java
            }
            task.builtins {
                java {}
            }
        }
    }
}1234567891011121314151617

Example 5: combine .proto in android studio project

compile 'com.google.protobuf:protobuf-java:3.1.0'
    compile 'com.google.protobuf:protoc:3.1.0'12