Comments (4)
I am trying to figure out how to include protos in the artifact of a Android library project. In Java project I can just include the files in the processResources
task, but it doesn't work for Android project. The process*Resources
tasks in Android is different from the ones in Java.
@mdusina any ideas?
from protobuf-gradle-plugin.
Sorry for taking so long. This is a known missing feature, which is marked as a TODO in the source code. I didn't do it partially because the doubt of whether this feature would be needed, and that I was not familiar with Android development thus I was not sure I could do it right.
from protobuf-gradle-plugin.
My way of solving problem with import proto files from android library (project).
If android library is local and connected this way:
compile project(':androidlibrary')
I didn't find the way to put proto files in .aar (android library package). But I created external only java library with only proto files and connect it to our android library:
compile project(':androidlibraryproto')
This way all protobuf files remain in jar file of androidLibraryProto
library within .aar and you can successfully import proto files from you App.
androidlibraryproto.gradle
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
configurations {
grpcCompile
}
sourceSets {
grpc {
compileClasspath += configurations.grpcCompile
}
test {
compileClasspath += grpc.output
runtimeClasspath += grpc.output
}
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
dependencies {
compile 'com.google.protobuf:protobuf-java:3.2.0'
grpcCompile 'io.grpc:grpc-stub:1.0.0-pre2'
grpcCompile 'io.grpc:grpc-protobuf:1.0.0-pre2'
compile 'io.grpc:grpc-okhttp:1.0.3'
compile 'io.grpc:grpc-protobuf:1.0.3'
compile 'io.grpc:grpc-stub:1.0.3'
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.0.0-pre2'
}
}
generateProtoTasks {
ofSourceSet('grpc').each { task ->
task.plugins {
grpc {
outputSubDir = 'grpc_output'
}
}
task.generateDescriptorSet = true
}
}
}
project.afterEvaluate { compileJava.dependsOn generateSources }
jar {
sourceSets.all { sourceSet ->
from sourceSet.output
dependsOn sourceSet.getCompileTaskName('java')
}
}
androidlibrary.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'
android {...}
dependencies {
compile project(':androidlibraryproto')
...
}
app.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {...}
dependencies {
compile project(':androidlibrary')
...
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.0.3'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {}
}
task.plugins {
grpc {}
}
generateSources.dependsOn task
}
}
}
When we decided to upload android library to JCenter and use this way:
compile "com.github.username:androidlibrary:0.0.1"
This way we can't leave compile project(':androidlibraryproto')
in dependencies, because when we'll compile libarary from JCenter then an error will occur - can't get androidlibraryproto library
.
We have to ways:
- get Jar package from
androidlibraryproto
, copy it toandroidlibrary/libs
, compile this way:compile files("libs/andoridlibraryproto")
and upload it to JCenter.
This way unreal now, because proto files not extracted from .aar package. I think for using this way you should add .aar to this line - upload
androidlibraryproto
to JCenter and connect toandroidlibrary
andApp
this waycompile "com.github.username:androidlibraryproto:0.0.1"
Then we can compile our android library in app.gradle this way:
protobuf ("com.github.username:androidlibraryproto:0.0.1") {
transitive = false // To avoid duplicate zip entry error when minifyEnabled
}
compile ("com.github.username:androidlibrary:0.0.1") {
transitive = false // To avoid duplicate zip entry error when minifyEnabled
}
Now I'm using last way, I uploaded proto files to JCenter separately and compile it in app.grade
and androidlibrary.gradle
from protobuf-gradle-plugin.
Seems this was probably fixed by #440.
from protobuf-gradle-plugin.
Related Issues (20)
- Could not find method protobuf() HOT 5
- Task generateProto is not executed before task compileJava during build in version 0.9.3 HOT 7
- How to avoid package proto files into apk HOT 1
- Unable to use lite version - multiple versions of class HOT 31
- How config proto src dir when proto files import by path HOT 2
- Java keyword "public" not escaped during proto generation HOT 1
- doc improvement HOT 1
- How can I disable registering the generated Java code as sources? HOT 7
- KSP dependency on generateProto - unable to build project due to KspTaskJvm issue HOT 1
- Fail on protoc warnings HOT 1
- Feature Request: Allow configuration of java executable HOT 2
- Kotlin only generated classes HOT 2
- extractIncludeProto execute so slowly
- protobuf dependency configuration is marked consumable
- Gradle Java project running into many proto related errors "cannot find symbol" randomly on compiling Java srcs
- Plugin not compiling java code after migration from 0.8.19 -> 0.9.0 HOT 8
- Update sample to use latest plugin version HOT 1
- How can I compile proto files using Protobuf Editions
- Compilation of the generated code fails with protobuf 4.26.0 HOT 3
- Example/documentation for generating kotlin classes with kotlin DSL HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-gradle-plugin.