Giter Club home page Giter Club logo

Comments (3)

aantono avatar aantono commented on June 17, 2024

I am not at length familiar with the android build declaration/configuration in Gradle.
Can you shed some light onto what exactly is not compatible?
From your comment, I assume the Android build does not use 'java' plugin, but something else?

from gradle-plugin-protobuf.

sorccu avatar sorccu commented on June 17, 2024

There's a way to make it work. First of all, you'll have to create a new Java library module in your project just for the protos. Then, if you follow the instructions in the README, gradle will already happily build your project. Unfortunately, Android Studio will not see the generated files with the default Gradle configuration, which ignores the whole build directory. It will still build, but you won't get autocomplete and you'll get unresolved symbol errors in the editor. I was able to get it to work with the following configuration:

proto/build.gradle

apply plugin: 'protobuf'
apply plugin: 'idea'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'ws.antonov.gradle.plugins:gradle-plugin-protobuf:0.8'
    }
}

idea {
    module {
        // The whole build dir is excluded by default, but we need build/generated-sources,
        // which contains the generated proto classes.
        excludeDirs = [
                file('.gradle'),
                file("$buildDir/classes"),
                file("$buildDir/docs"),
                file("$buildDir/dependency-cache"),
                file("$buildDir/libs"),
                file("$buildDir/reports"),
                file("$buildDir/resources"),
                file("$buildDir/test-results"),
                file("$buildDir/tmp"),
        ]
    }
}

dependencies {
    compile group: 'com.google.protobuf', name: 'protobuf-java', version: '2.5.0'
}

protocPath = '/usr/local/bin/protoc'

app/build.gradle

dependencies {
    // ...
    compile project(':proto')
    // ...
}

settings.gradle

include ':app', ':proto'

Hope this saves someone else some time. Alternatively, changing generatedFileDir should work also, but I prefer to have all build artifacts in the build dir.

from gradle-plugin-protobuf.

louiscryan avatar louiscryan commented on June 17, 2024

A slight more succinct and reliable way of achieving the same effect...

excludeDirs = [file('.gradle')]
if (buildDir.exists()) {
excludeDirs += files(buildDir.listFiles())
excludeDirs -= file("$buildDir/generated-sources")
}

from gradle-plugin-protobuf.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.