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

Open
sourcesoftankit opened this issue Nov 20, 2018 · 3 comments

Comments

@sourcesoftankit
Copy link

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.