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

Is protobuf-kotlin-lite a Kotlin equivalent of protobuf-javalite? #499

Closed
marosseleng opened this issue May 23, 2021 · 5 comments
Closed

Comments

@marosseleng
Copy link

Hi guys,

basically, the question is in the title. I was following Google's codelab on Android DataStore backed by protocol buffers and they use -javalite artifact for protobuf.

Firstly, I set up the configuration as in the codelab (java bindings), but after a while, I noticed that Kotlin is also supported. So I updated the dependencies and replaced protobuf-javalite with protobuf-kotlin-lite:3.17.0. The modified build.gradle is as follows:

plugins {
    ...
    id 'com.google.protobuf' version '0.8.16'
}
...
dependencies {
    ...
    implementation 'com.google.protobuf:protobuf-kotlin-lite:3.17.0'
}
protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.17.0"
    }

    generateProtoTasks {
        all().each { task ->
            task.builtins {
                kotlin {
                    option 'lite'
                }
            }
        }
    }
}

However, on build, I am getting errors like these:

> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-javalite-3.17.0 (com.google.protobuf:protobuf-javalite:3.17.0) and jetified-protobuf-kotlin-lite-3.17.0 (com.google.protobuf:protobuf-kotlin-lite:3.17.0)
 Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules jetified-protobuf-javalite-3.17.0 (com.google.protobuf:protobuf-javalite:3.17.0) and jetified-protobuf-kotlin-lite-3.17.0 (com.google.protobuf:protobuf-kotlin-lite:3.17.0)
 Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules jetified-protobuf-javalite-3.17.0 (com.google.protobuf:protobuf-javalite:3.17.0) and jetified-protobuf-kotlin-lite-3.17.0 (com.google.protobuf:protobuf-kotlin-lite:3.17.0)
 Duplicate class com.google.protobuf.AbstractMessageLite$InternalOneOfEnum found in modules jetified-protobuf-javalite-3.17.0 (com.google.protobuf:protobuf-javalite:3.17.0) and jetified-protobuf-kotlin-lite-3.17.0 (com.google.protobuf:protobuf-kotlin-lite:3.17.0)
 Duplicate class com.google.protobuf.AbstractParser found in modules jetified-protobuf-javalite-3.17.0 (com.google.protobuf:protobuf-javalite:3.17.0) and jetified-protobuf-kotlin-lite-3.17.0 (com.google.protobuf:protobuf-kotlin-lite:3.17.0)
 Duplicate class com.google.protobuf.AbstractProtobufList found in modules jetified-protobuf-javalite-3.17.0 (com.google.protobuf:protobuf-javalite:3.17.0) and jetified-protobuf-kotlin-lite-3.17.0 (com.google.protobuf:protobuf-kotlin-lite:3.17.0)
 Duplicate class com.google.protobuf.AllocatedBuffer found in modules jetified-protobuf-javalite-3.17.0 (com.google.protobuf:protobuf-javalite:3.17.0) and jetified-protobuf-kotlin-lite-3.17.0 (com.google.protobuf:protobuf-kotlin-lite:3.17.0)

and so on.

Am I doing something wrong? Isn't kotlin-lite an equivalent of javalite?

@ejona86
Copy link
Collaborator

ejona86 commented May 24, 2021

This repo is just for the gradle plugin; this seems a question better suited to the protobuf or protobuf-kotlin projects although in this case I think the problem isn't even with those projects.

"Duplicate class" means that there is ambiguity for which class should be used. jetified-protobuf-javalite seems to duplicate the classes of protobuf-javalite, so you can only have a dependency on one of those two libraries. I'm not familiar with the jetified version, but it is clearly causing trouble. It seems protobuf-kotlin-lite depends on the normal protobuf-javalite. I'd assume you have some other dependency (not shown in the code snippet) that is bringing in the jetified version which is causing your pain. I don't know who created the jetified version, but I'm very disappointed to see it.

@marosseleng
Copy link
Author

@ejona86 From what I found out, the only javalite comes from protobuf-kotlin-lite. I do have jetifier enabled, maybe that could be a cause? Is there something to jetify within javalite? Those should be non-android libraries, right?

@ejona86
Copy link
Collaborator

ejona86 commented May 24, 2021

I don't know why there are jetifier versions of these binaries. I've not really used jetifier.

@marosseleng
Copy link
Author

I've got that set up as the part of android project. Now I am using only androidx libraries, so Jetifier shouldn't be necessary. Anyways, I disabled Jetifier, which made those duplication errors disappear, but now it seems that protobuf isn't generating the Kotlin file for the original message defined in .proto file:

syntax = "proto3";

option java_package = "com.marosseleng.example.datastore";
option java_multiple_files = true;

// reserve 1-15 for most frequently used. Those fields occupy 1 byte
// fields 16-2049 take 2 bytes.
message UserPreferences {
  bool onboarding_completed = 1;
}

I can see generated UserPreferencesKt.kt file that has lots of unresolved references to com.marosseleng.example.datastore.UserPreferences and there is also UserPrefsKt.kt (name corresponds to my protobuf file name) file which is empty. So I am still guessing whether something's wrong with the configuration.

I haven't find anything special regarding syntax in proto file or gradle compiler.

@marosseleng
Copy link
Author

So I looked into protobuf repo here on Github and there is already this issue (protocolbuffers/protobuf#8631). This one thus might be closed, it really isn't issue of gradle plugin.

Thanks for help anyways!

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

2 participants