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

Kotlin library cause duplicate file error #8694

Closed
JeroenMols opened this issue Jun 4, 2021 · 2 comments
Closed

Kotlin library cause duplicate file error #8694

JeroenMols opened this issue Jun 4, 2021 · 2 comments
Assignees

Comments

@JeroenMols
Copy link

JeroenMols commented Jun 4, 2021

What version of protobuf and what language are you using?
Version: v3.17.2
Language: Kotlin

What operating system (Linux, Windows, ...) and version?
OSX 11.4

What runtime / compiler are you using (e.g., python version or gcc version)
Protoc version 3.17.2
Gradle version 7.0.2
Android Studio 4.2.1

What did you do?
Steps to reproduce the behavior:

  1. Create a new Android studio project
  2. Add dependency on com.google.protobuf:protobuf-kotlin:3.17.2
  3. Build project
  4. See error

What did you expect to see
Project builds successfully

What did you see instead?
Gradle outputs the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
   > 2 files found with path 'google/protobuf/field_mask.proto' from inputs:
      - /Users/jmols/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-kotlin/3.17.2/3edd99a5479d55c364eb75027d925ece524e77d5/protobuf-kotlin-3.17.2.jar
      - /Users/jmols/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/3.17.2/d7eec2ad499b605f24d07f49bdcb41c801aafbfc/protobuf-java-3.17.2.jar
     Adding a packagingOptions block may help, please refer to
     https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html
     for more information

As the error suggests, this is caused because both protobuf-kotlin and protobuf-java include the same *.proto files.

Screen Shot 2021-06-04 at 10 12 24 AM

This can be worked around by adding the following to your build.gradle file:

android {
    packagingOptions {
        pickFirst 'google/protobuf/*.proto'
        pickFirst 'google/protobuf/compiler/*.proto'
    }
}

This however is not an option for us as we ship protobuf-kotlin as a transitive dependency in our SDK. Hence this would require all our customers to add this to their build.gradle file, which increases the integration effort or our SDK.

Note: this issue is very similar to #8631, though now the conflict arrises from duplicate .proto files instead of source files.

Anything else we should know about your project / environment

@JeroenMols JeroenMols changed the title Kotlin library Kotlin library cause duplicate file error Jun 4, 2021
@deannagarcia
Copy link
Member

Thanks for reporting this! I am working on a fix and an associated point release.

@JeroenMols
Copy link
Author

JeroenMols commented Jun 9, 2021

Verified this on 3.17.3, thanks for the quick fix!

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