Objectbox-java: DexArchiveMergerException

Created on 21 Jun 2018  路  7Comments  路  Source: objectbox/objectbox-java

I followed the tutorial to add the ObjectBox to my Andoird project. After adding Entity with Annotation, and then build, Compilation failed to complete appeared.
Possible dependency conflict problems.

`buildscript {
ext.kotlin_version = '1.2.50'
ext.objectboxVersion = '1.5.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.ar.sceneform:plugin:1.0.1'
}
}

allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}`

`apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt' // if using Kotlin

apply plugin: 'com.google.ar.sceneform.plugin'

apply plugin: 'io.objectbox'`

error

All 7 comments

Try classpath 'com.android.tools.build:gradle:3.1.2' instead of classpath 'com.android.tools.build:gradle:3.1.3'

@ToadPrincess Judging from the FlatBufferBuilder error message: Have you included the source code of Flatbuffers in your code?

ObjectBox has a dependency on the Flatbuffers library that may conflict with your copy of the classes. Try to remove the Flatbuffers source code from your code and add the Flatbuffers library as a dependency instead.

Or exclude the Flatbuffers dependency completely using:

configurations.all {
    exclude group: 'com.google.flatbuffers', module: 'flatbuffers-java'
}

However, this solution might stop working in the future. ObjectBox code might use FlatBuffers API functionality in the future that is not present in the version packaged by AR core.

Update 2020-08-11: updated workaround.

No response, closing. Please re-open with more details or submit a new issue. -ut

just remove
apply plugin: 'io.objectbox'

and manually add

 implementation ("io.objectbox:objectbox-android:$objectboxVersion"){
      exclude group: 'com.google.flatbuffers', module: 'flatbuffers-java'
 }
 implementation ("io.objectbox:objectbox-kotlin:$objectboxVersion"){
      exclude group: 'com.google.flatbuffers', module: 'flatbuffers-java'
 }
 kapt ("io.objectbox:objectbox-processor:$objectboxVersion")

@dpproduction Actually do not remove the apply statement. The plugin also configures other things besides those dependencies (e.g. byte-code transformation).

Also try this instead:

configurations.all {
    exclude group: 'com.google.flatbuffers', module: 'flatbuffers-java'
}

However, this solution might stop working in the future. ObjectBox code might use FlatBuffers API functionality in the future that is not present in the version packaged by AR core.

Update 2020-08-11: updated workaround.

@greenrobot-team I have the same issue of duplicated dependencies (between ObjectBox and GoogleArCore Sceneform):
Duplicate class com.google.flatbuffers.Constants found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)
Duplicate class com.google.flatbuffers.FlatBufferBuilder found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)
Duplicate class com.google.flatbuffers.FlatBufferBuilder$ByteBufferFactory found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)
Duplicate class com.google.flatbuffers.FlatBufferBuilder$HeapByteBufferFactory found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)
Duplicate class com.google.flatbuffers.Struct found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)
Duplicate class com.google.flatbuffers.Table found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)
Duplicate class com.google.flatbuffers.Utf8 found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)
Duplicate class com.google.flatbuffers.Utf8Safe found in modules jetified-flatbuffers-java-1.12.0.jar (com.google.flatbuffers:flatbuffers-java:1.12.0) and jetified-sceneform-base-1.15.0-runtime.jar (com.google.ar.sceneform:sceneform-base:1.15.0)

If I follow the solution of @dpproduction everything works right. I mean adding:
implementation ("io.objectbox:objectbox-android:$objectboxVersion"){
exclude group: 'com.google.flatbuffers', module: 'flatbuffers-java'
}
annotationProcessor "io.objectbox:objectbox-processor:$objectboxVersion"

and removing the "apply plugin: 'io.objectbox'".
However I'm afraid of what you said of avoid removing the apply plugin.

I tried to add apply plugin: 'io.objectbox' in every ways (after dependencies block, at the beggining of the build.gradle app file, after the apply plugin: 'com.android.application') but nothing worked. Just removing the apply plugin.

Is there any solutions? What does it happen if I haven't the apply plugin? The ObjectBox library will work with errors?

Thanks!!

Please, any update of this issue? @greenrobot-team @greenrobot
I need to know if I could use and trust in ObjectBox for my mobile app or not .

Was this page helpful?
0 / 5 - 0 ratings