3

Every example I can find of configuring build.gradle to compile protobufs uses the "lite" version and looks something like this:

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.6.0'
    }
    plugins {
        javalite {
            artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                remove java
            }
            task.plugins {
                javalite { }
            }
        }
    }
}

dependencies {
    implementation 'com.google.protobuf:protobuf-java:3.6.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Note the "javalite". This results in generated java files that use MessageLite, but I need the full Message class.

How do I change this so that it does not generate the "lite" version?

JamieB
  • 703
  • 1
  • 6
  • 17
  • Do you know why recommend "lite" version for android? because normal protobuf uses runtime reflection and generated classes are more complex, And it's not efficient for Android! using normal version take effect on application performance. – beigirad Feb 14 '19 at 07:34
  • 1
    Yes but if you want to pack a message into an Any.proto, you need it to be a Message not a MessageLite. – JamieB Feb 14 '19 at 16:01

1 Answers1

3

Found the solution:

1) Remove this:

plugins {
    javalite {
        artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
    }
}

2) Remove this:

task.plugins {
    javalite { }
}

3) Change the task.builtins section to this:

task.builtins {
    java { }
}

It will now generate the full featured protobuffs.

JamieB
  • 703
  • 1
  • 6
  • 17