Search code examples
androidandroid-gradle-pluginbuild.gradlemaven-pluginsquare

Generate Protobuf java files with Square's Wire


I'm trying to generate .java files from the .proto files I have stored under my SRC folder in Android studio. I put the below code in my gradle file by it doesn't seem to work

apply plugin: 'com.squareup.wire'

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'com.squareup.wire:wire-maven-plugin:2.1.1'
  }
}

Solution

  • So instead of using a gradle plugin I just ended up using the square wire compiler jar. Here are the steps.

    1. Download compiler-jar-with-dependencies from http://search.maven.org/#artifactdetails%7Ccom.squareup.wire%7Cwire-compiler%7C2.1.1%7Cjar
    2. Put jar file into root directory of android app
    3. Go to the directory and paste this command

      java -jar wire-compiler-2.1.1-jar-with-dependencies.jar --proto_path=directory-of-protofile --java_out=app/src/main/java/ name-of-file.proto
      

    Should work. Make sure to replace the directory-of-protofile and name-of-file with whatever you have.