Error after adding boofcv-core to Android: java.lang.RuntimeException: Duplicate class com.google.protobuf

101 Views Asked by At

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'
    }
...
1

There are 1 best solutions below

4
On

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.