2

I`m trying to add boofcv-core library to my Android project. boofcv-android works fine but boofcv-core generates the following error: java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.17.3.jar (com.google.protobuf:protobuf-java:3.17.3) and protobuf-javalite-3.14.0.jar (com.google.protobuf:protobuf-javalite:3.14.0)...

The code at build.gradle:

...
configurations {
//    compile.exclude group: 'com.google.protobuf' // when uncommented, causes other errors
    all*.exclude group: "xmlpull", module: "xmlpull"
    all*.exclude group: "org.apache.commons", module: "commons-compress"
    all*.exclude group: "com.thoughtworks.xstream", module: "commons-compress"
}

dependencies {
    ['boofcv-android', 'boofcv-core'].each {
        String a -> implementation group: 'org.boofcv', name: a, version: '0.37'
    }
...
Sher Mi
  • 548
  • 2
  • 5
  • 14

1 Answers1

3

Solved: protobuf-java(dependency inside boofcv-core) and protobuf-javalite(dependency inside firebase) cant exist together- full explanation here. After generating a dependency tree(./gradlew app:dependencies), I noticed that only boofcv-geo and boofcv-recognition (libraries inside boofcv-core - see link) depend on protobuf-java. I have no need in these 2 libraries so I excluded them from compilation. At app/build.gradle, add:

...
configurations {
    compile.exclude group: 'org.boofcv',module: 'boofcv-recognition' //<-- added
    compile.exclude group: 'org.boofcv',module: 'boofcv-geo' //<-- added
    all*.exclude group: "xmlpull", module: "xmlpull"
    all*.exclude group: "org.apache.commons", module: "commons-compress"
    all*.exclude group: "com.thoughtworks.xstream", module: "commons-compress"
}
...

And then the error disappears.

Sher Mi
  • 548
  • 2
  • 5
  • 14
  • 2
    This is just a compile time exclusion? Removing 'boofcv-geo' entirely would break a lot of applications. When you specify a dependency via implements you can exclude a transitive dependency. – lessthanoptimal Nov 08 '22 at 15:36
  • 1
    Thank you for maintaining this great library! Could you explain the second sentence about transitive dependency? – Sher Mi Nov 09 '22 at 07:28
  • 1
    basically you should remove the protobuf dependency when you do `implementation(...)`. That way you won't end up with two protobuf libs at runtime. https://stackoverflow.com/questions/62868920/gradle-exclude-a-transitive-dependency – lessthanoptimal Nov 10 '22 at 22:43
  • @lessthanoptimal It has caused a whole new error: implementation "org.boofcv:boofcv-android:0.31" implementation (("org.boofcv:boofcv-core:0.38"), { exclude group: 'com.google.protobuf', module: 'protobuf-java' }) `java.lang.RuntimeException: Duplicate class boofcv.abst.geo.calibration.CalibrateMonoPlanar found in modules boofcv-calibration-0.31.jar (org.boofcv:boofcv-calibration:0.31) and boofcv-geo-0.38.jar (org.boofcv:boofcv-geo:0.38)` – Sher Mi Nov 13 '22 at 09:27