Skip to content

Duplicate class error when using TensorFlow-lite together #172

@L2zz

Description

@L2zz

Hi there!
I want to use TensorFlow-lite with arsceneview in the application.
However, I got a Duplicate class error with com.google.flatbuffers.*,
when I added both dependencies like below.

[build.gradle (:app)]

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.sceneview.andyoncylinder"
        minSdk 26
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    buildFeatures {
        mlModelBinding true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    aaptOptions {
        noCompress 'filamat', 'ktx', 'tflite'
    }
}

dependencies {
    def lifecycle_version = "2.5.1"
    implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.5.0'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.google.android.gms:play-services-auth:20+'
    implementation 'com.google.android.gms:play-services-location:19+'
    implementation 'com.google.android.gms:play-services-maps:18.0.2'
    implementation 'com.google.maps.android:android-maps-utils:2.4.0'

    // CSVReader
    implementation 'com.opencsv:opencsv:5.4'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'

    // Picasso
    implementation 'com.squareup.picasso:picasso:2.8'

    // arsceneview
    implementation 'io.github.sceneview:arsceneview:0.9.0'

    // tflite
    implementation 'org.tensorflow:tensorflow-lite:2.10.0'
    implementation 'org.tensorflow:tensorflow-lite-gpu:2.10.0'
    implementation 'org.tensorflow:tensorflow-lite-support:0.4.2'
    implementation 'org.tensorflow:tensorflow-lite-metadata:0.4.2'
}

[Error Log]

Duplicate class com.google.flatbuffers.Constants found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.FlatBufferBuilder found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.FlatBufferBuilder$ByteBufferBackedInputStream found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.FlatBufferBuilder$ByteBufferFactory found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.FlatBufferBuilder$HeapByteBufferFactory found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Struct found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Table found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Table$1 found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Utf8 found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Utf8$DecodeUtil found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Utf8$UnpairedSurrogateException found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Utf8Safe found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)
Duplicate class com.google.flatbuffers.Utf8Safe$UnpairedSurrogateException found in modules flatbuffers-java-1.12.0 (com.google.flatbuffers:flatbuffers-java:1.12.0) and sceneview-0.9.0-runtime (io.github.sceneview:sceneview:0.9.0)

Go to the documentation to learn how to Fix dependency resolution errors.

I read how to Fix dependency resolution errors and some issues (1), (2) points out sceneform makes conficts.

Therefore, I think this problem is from flatbuffers in sceneform,
and flatbuffers (com.google.flatbuffers:flatbuffers-java:1.12.0) in TensorFlow-lite are conflicted.

As sceneview-1.0.0 escapes from the sceneform dependency, I tried to use it.
However, the dependency of arsceneview-1.0.0 is still tied to arsceneview-0.9.0, which caused the problem.

Excluding a module from arsceneview or TensorFlow-lite is not a solution because I have to use flatbuffers on both arsceneview and TensorFlow-lite. (Function does not work when excluding flatbuffers)

Is there any solution other than waiting for an update?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions