stripe-android icon indicating copy to clipboard operation
stripe-android copied to clipboard

[BUG] Duplicate class org.tensorflow.lite

Open VinuPolly-Bonnet opened this issue 1 year ago • 3 comments

Summary

When trying to include the Tensorflow lite library in the gradle, the build process fails with duplicate classes issue. This is observed if the we include the stripe card scan library for the scanning functionality within Stripe.

Code to reproduce

Add the following in the app level gradle and try to build the app

/* Stripe */
implementation 'com.stripe:stripe-android:20.39.0'
implementation 'com.stripe:stripecardscan:20.39.0'
implementation 'org.tensorflow:tensorflow-lite:2.15.0'

The defaultConfig values are,

defaultConfig {
        //.....
        minSdkVersion 26
        targetSdkVersion 34
        compileSdk 34
        //....
    }

Impacted devices

Couldn't get successful build

Installation method

gradle dependency

Dependency Versions

kotlin: 1.9.0 stripe-android: 20.39.0 Android Gradle Plugin: 8.3.0 Gradle: gradle-8.4-bin.zip

Other information

Build error log:

Duplicate class org.tensorflow.lite.DataType found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.DataType$1 found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.Delegate found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.Interpreter found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-2.15.0-runtime (org.tensorflow:tensorflow-lite:2.15.0)
Duplicate class org.tensorflow.lite.Interpreter$Options found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-2.15.0-runtime (org.tensorflow:tensorflow-lite:2.15.0)
Duplicate class org.tensorflow.lite.NativeInterpreterWrapper found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-2.15.0-runtime (org.tensorflow:tensorflow-lite:2.15.0)
Duplicate class org.tensorflow.lite.Tensor found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.Tensor$QuantizationParams found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.TensorFlowLite found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.annotations.UsedByReflection found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.nnapi.NnApiDelegate found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)
Duplicate class org.tensorflow.lite.nnapi.NnApiDelegate$Options found in modules jetified-stripecardscan-tflite-20.39.0-runtime (com.stripe:stripecardscan-tflite:20.39.0) and jetified-tensorflow-lite-api-2.15.0-runtime (org.tensorflow:tensorflow-lite-api:2.15.0)


VinuPolly-Bonnet avatar Mar 27 '24 15:03 VinuPolly-Bonnet

Hi @jaynewstrom-stripe @ccen-stripe just checking in, is there any workaround for this problem? Need to use tflite in our project for a new requirement. Thanks

VinuPolly-Bonnet avatar Mar 31 '24 21:03 VinuPolly-Bonnet

hi @VinuPolly-Bonnet cardscan uses an different internal tensorlow dep, causing a conflict of classes, to use it with the default tflite runtime, please update the corresponding stripe related tflite modules as follows -

implementation('com.stripe:stripe-android:20.40.4')
implementation('com.stripe:stripecardscan:20.40.4') {
    exclude group: 'com.stripe', module: 'ml-core-cardscan' // exclude the cardscan-specific portable tflite runtime
}

implementation('com.stripe:ml-core-default:20.40.4') // include ml-core-default, which has org.tensorflow:tensorflow-lite

// no need to declare org.tensorflow:tensorflow-lite explicitly

With this change you'll be able to use cardscan and org.tensorflow.lite.Interpreter in the app.

Please note we're currently still using 2.11.0 for org.tensorflow:tensorflow-lite, will update this to 2.15.0 in the upcoming release

ccen-stripe avatar Apr 08 '24 17:04 ccen-stripe

Hi @ccen-stripe , will try this out soon, thanks for the assistance, any news when will the 2.15.0 version support will be available?

VinuPolly-Bonnet avatar May 08 '24 21:05 VinuPolly-Bonnet

@VinuPolly-Bonnet We haven't heard from you in a bit, so we're going to close this issue. Please reopen if needed!

jaynewstrom-stripe avatar Jun 17 '24 17:06 jaynewstrom-stripe