There are 3 modules in the project: app, app-common, app-native.
app-common is a Java module that contains the .proto classes that get compiled to Java. Both other modules will depend on the Java classes.
app-native is an Android module that contains a C++ library that also needs to compile the same .proto classes but in C++ (and also depends on the Java classes).
app depends on both.
At the moment, since app-native requires both Java and C++ compiled protobuf classes it declares 2 dependencies:
implementation project(path: ':app-common') // Java dependencies
protobuf project(path: ':app-common') // .proto files to be recompiled but in C++
This leads to duplicate .proto files when merging:
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
> 2 files found with path 'Foo.proto' from inputs:
- /Users/..../app-native/build/intermediates/library_java_res/debug/res.jar
- /Users/.../app-common/build/libs/app-common.jar
Adding packaging options to app-native e.g. resources.excludes.add("*.proto") seems to have no effects.
Excluding the .proto from app-common (jar { exclude '**/*.proto') somewhat works for the user defined protos, but still fails with the same error caused bygoogle/protobuf/Foo.proto` instead.
I realise the project configuration might be unconventional but I don't know what an alternative could be, so any help is appreciated.
There are 3 modules in the project:
app
,app-common
,app-native
.app-common
is a Java module that contains the.proto
classes that get compiled to Java. Both other modules will depend on the Java classes.app-native
is an Android module that contains a C++ library that also needs to compile the same.proto
classes but in C++ (and also depends on the Java classes).app
depends on both.At the moment, since
app-native
requires both Java and C++ compiled protobuf classes it declares 2 dependencies:This leads to duplicate .proto files when merging:
Adding packaging options to
app-native
e.g.resources.excludes.add("*.proto")
seems to have no effects. Excluding the.proto
fromapp-common
(jar { exclude '**/*.proto') somewhat works for the user defined protos, but still fails with the same error caused by
google/protobuf/Foo.proto` instead.I realise the project configuration might be unconventional but I don't know what an alternative could be, so any help is appreciated.