Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find JsonFormat class in Android #276

Closed
sourcesoftankit opened this issue Nov 20, 2018 · 6 comments
Closed

Unable to find JsonFormat class in Android #276

sourcesoftankit opened this issue Nov 20, 2018 · 6 comments

Comments

@sourcesoftankit
Copy link

sourcesoftankit commented Nov 20, 2018

I am using "Protobuf" library in android, and My business logic required to convert Proto format to Json so i need JsonFormat class for that but i am not able to find the "com.google.protobuf.util.JsonFormat" class and even com.google.protobuf.util package also.

I am using lite version of Protobuf and My gradle entry for protobuf is

 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'
    }
}
generateProtoTasks {
    all().each { task ->
        task.builtins {
            remove java
        }
        task.plugins {
             javalite { }
           }
       }
   }
}

  dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.protobuf:protobuf-lite:3.0.0'

}

And in my project level gradle:

   dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
  }
@ejona86
Copy link
Collaborator

ejona86 commented Nov 20, 2018

This has nothing to do with this plugin, since com.google.protobuf.util isn't generated code.

But in short, com.google.protobuf.util is in a different artifact, protobuf-java-util. And it doesn't work with protobuf-lite. Using the JSON conversion is unsupported on Android, as Lite does not include the necessary descriptors (as they would increase the apk size too much).

@sourcesoftankit
Copy link
Author

sourcesoftankit commented Nov 21, 2018

Thanks @ejona86 for the quick revert.
There is any alternate to convert protobuf to JSON or existing POJO in android.

@ejona86
Copy link
Collaborator

ejona86 commented Nov 21, 2018

I'm not aware of any, but I'm not in-the-know enough to say if someone else has made something. We tend to think that conversions like that shouldn't be happening in an Android app (due to app size), so we design the system differently.

@cepages
Copy link

cepages commented Oct 8, 2019

@sourcesoftankit did you find any alternative to convert the protobuf generated to JSON?

@ejona86 ejona86 closed this as completed Oct 8, 2019
@cepages
Copy link

cepages commented Oct 10, 2019

If it helps to anyone. I've described the problem and the solution in a thread in google forums.

Solution, using protobuf-java instead of javalite

https://groups.google.com/forum/#!topic/protobuf/EC2TtPixCFY

@rakshitsoni02
Copy link

is there any good solution except using protobuf-java instead of javalite?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants