One file has both java and javalite version

513 views
Skip to first unread message

gqqn...@gmail.com

unread,
Jul 16, 2017, 2:21:44 AM7/16/17
to grpc.io
This is my build.gradle.

apply plugin: 'java'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'io.grpc:grpc-okhttp:1.4.0'
compile 'io.grpc:grpc-protobuf-lite:1.4.0'
compile 'io.grpc:grpc-stub:1.4.0'
compile 'javax.annotation:javax.annotation-api:1.2'
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"


apply plugin: 'com.google.protobuf'

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
}
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.0.0' // CURRENT_GRPC_VERSION
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {}
grpc {
// Options added to --grpc_out
option 'lite'
}
}
}
}
}


I copied hellowworld.proto to my module. Once I make the module, Android Studio gives error Duplicated class io.grpc.examples.helloworld.HelloReply. I searched the file explorer, the same class exists in build\generated\source\proto\main\java\io\grpc\examples\helloworld\HelloReply.java and D:\SimpleChat\protocol\build\generated\source\proto\main\javalite\io\grpc\examples\helloworld\HelloReply.java.



I checked the sample repository in https://github.com/grpc/grpc-java, it only has the java one.

How do I resolve this?



Eric Gribkoff

unread,
Jul 16, 2017, 2:40:01 PM7/16/17
to gqqn...@gmail.com, grpc.io
Can you try "./gradlew clean" and then rebuild? You can encounter this type of error when you've already built a project using one flavor of protobuf, then switch to another. The generated files from the old proto flavor are not always removed automatically, causing conflicts, but "./gradlew clean" will clear them out.

Thanks,

Eric

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/2071b2d9-9168-4b20-83ec-769215328a83%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gqqn...@gmail.com

unread,
Jul 16, 2017, 4:54:22 PM7/16/17
to grpc.io, gqqn...@gmail.com
I think I figured out, I have to remove javalite {} in generateProtoTasks section.

You are so helpful, thanks

在 2017年7月16日星期日 UTC-7上午11:40:01,Eric Gribkoff写道:
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

gqqn...@gmail.com

unread,
Jul 16, 2017, 6:51:27 PM7/16/17
to grpc.io, gqqn...@gmail.com
I now have another problem. Do you midn looking again?

I make the project, but Android Studio cannot find many packages.. See the screenshot.



I already have 


dependencies {

compile 'io.grpc:grpc-okhttp:1.4.0'
compile 'io.grpc:grpc-protobuf-lite:1.4.0'
compile 'io.grpc:grpc-stub:1.4.0'
compile 'javax.annotation:javax.annotation-api:1.2'
}

in build.gradle.

Am I still missing anything?

在 2017年7月16日星期日 UTC-7上午11:40:01,Eric Gribkoff写道:
Can you try "./gradlew clean" and then rebuild? You can encounter this type of error when you've already built a project using one flavor of protobuf, then switch to another. The generated files from the old proto flavor are not always removed automatically, causing conflicts, but "./gradlew clean" will clear them out.

Thanks,

Eric

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

Eric Gribkoff

unread,
Jul 18, 2017, 4:48:09 PM7/18/17
to gqq nbig, grpc.io
You still need the javalite {} block in both protobuf.plugins and protobuf.generateProtoTasks. I would suggest following these instructions to build the example gRPC Android Hello World app (here is its build.gradle), confirm the example builds in your local environment then adapt the working example to your project. If the Hello World app doesn't build for you, let me know.

Best,

Eric

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.

gqqn...@gmail.com

unread,
Jul 19, 2017, 12:57:47 AM7/19/17
to grpc.io, gqqn...@gmail.com
Yes, the example project builds perfectly. But as soon as I copy settings over to my projects, things start to break.

I'm new to Android, Gradle, and gRPC, so it's too easy for me to miss anything.. Sorry to borther.

From a beginner's point of view, the example project is too complicated and is not only "hello world". It's like a sub project in gRPC project and contains advanced examples, so I'm not sure which settings/codes are essential to the simplest helloworld demo, and it  isn't organized in Android Studio‘s way.. It's just my two cents.

I use Android Studio and my project structure is this, I have an Android  module named as Client, and a Java module named as Protocol.  Protocol module contains proto files and generates necessary gRPC classes. Client module references Protocol, and in the future when I create a Server module, it could also reference Protocol module..

I committed the project to GitHub. I would so appreciate if you could clone my debug branch and take a look.

git clone -b debug https://github.com/gqqnbig/SimpleChat2017

在 2017年7月18日星期二 UTC-7下午1:48:09,Eric Gribkoff写道:
Eric

Eric Gribkoff

unread,
Jul 19, 2017, 2:25:15 PM7/19/17
to gqq nbig, grpc.io
It's probably not a good idea to try to include your server and Android app in the same project; at the least, you should not be trying to run a gRPC server via Android Studio. You need your server to depend on grpc-netty, and this is not intended/supported for Android. 

I would suggest creating two projects, one for Android, one for your server, and just copy and modify the existing examples to create each project. If you want to share the same .proto definitions between the projects, just put the protos in a separate project that the other two depend on.

Hope this helps.

Eric

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
Reply all
Reply to author
Forward
0 new messages