How to build Google protocol buffers and Kotlin using Gradle?

前端 未结 3 1387
灰色年华
灰色年华 2021-02-13 05:07

I\'m trying to build a project that uses both Google protocol buffers and Kotlin using Gradle. I want the proto files to compile into Java source, which is then called from my K

3条回答
  •  孤城傲影
    2021-02-13 05:08

    For Kotlin and Android:

    android {
    
        sourceSets {
            debug.java.srcDirs += 'build/generated/source/proto/debug/java'
            release.java.srcDirs += 'build/generated/source/proto/release/java'
        }
    }
    

    An additional source directory has to be added for every build type. In this sample there are two build types: debug and release.

    If you're using grpc, another line has to be added per build type:

    android {
    
        sourceSets {
            debug.java.srcDirs += 'build/generated/source/proto/debug/java'
            debug.java.srcDirs += 'build/generated/source/proto/debug/grpc'
            release.java.srcDirs += 'build/generated/source/proto/release/java'
            release.java.srcDirs += 'build/generated/source/proto/release/grpc'
        }
    }
    

    At least with Kotlin 1.0.6, protobuf-gradle-plugin 0.8.0, protobuf 3.2.x and grpc 1.x it's not required to fiddle with the task order.

提交回复
热议问题