stripe / stripe-android

Stripe Android SDK
https://stripe.com/docs/mobile/android
MIT License
1.26k stars 639 forks source link

[BUG] Duplicate class com.stripe.android.uicore.address.AddressRepository_Factory #6590

Closed malua closed 1 year ago

malua commented 1 year ago

Summary

I am following the guide to enable Google Pay for our Android app. But by adding the SDK like shown in the docs implementation 'com.stripe:stripe-android:20.23.1'

I get the following error when building:

Duplicate class com.stripe.android.uicore.address.AddressRepository_Factory found in 
modules jetified-identity-20.19.5-runtime (com.stripe:identity:20.19.5) and jetified-link-20.23.1-runtime (com.stripe:link:20.23.1)

When I use 20.19.5 the error goes away and Google Pay works. Is there a way to force one of the 2 implementations?

Code to reproduce

Android version

I am targeting Android API Level 32.

Installation method

The gradle dependency.

Dependency Versions

kotlin: ./gradlew :dependencies | grep kotlin - does not have any output stripe-android: does not have any output Android Gradle Plugin: does not have any output Gradle:

Gradle 7.4.2

Build time: 2022-03-31 15:25:29 UTC Revision: 540473b8118064efcc264694cbcaa4b677f61041

Kotlin: 1.5.31 Groovy: 3.0.9 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 11.0.11 (AdoptOpenJDK 11.0.11+9) OS: Mac OS X 11.2 x86_64

SDK classes

com.stripe.android.uicore.address.AddressRepository_Factory found in 
modules jetified-identity-20.19.5-runtime (com.stripe:identity:20.19.5) and jetified-link-20.23.1-runtime (com.stripe:link:20.23.1)
jaynewstrom-stripe commented 1 year ago

Hi @malua could you show us your build.gradle?

malua commented 1 year ago

Sure!

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "xxxxxxx"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        aaptOptions {
             // Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
             // Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
            ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
        }
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    flatDir{
        dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
    }
}

dependencies {
    implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
    implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation project(':capacitor-android')
    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
    implementation project(':capacitor-cordova-android-plugins')

    implementation 'com.android.support:multidex:1.0.3'

    // Stripe
    implementation 'com.stripe:stripe-android:20.19.5'
}

apply from: 'capacitor.build.gradle'

try {
    def servicesJSON = file('google-services.json')
    if (servicesJSON.text) {
        apply plugin: 'com.google.gms.google-services'
    }
} catch(Exception e) {
    logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}
jaynewstrom-stripe commented 1 year ago

It looks like your projects aren't using the same versions of the stripe SDKs (notably link is different).

Can you update your project to use a variable in all the places you use the stripe SDK?

If you search all the build.gradles for com.stripe: and update the version to match, it should fix your issue.

As for a long term fix, I'm looking into adding a BOM which should also help fix this issue in the future.

algera commented 1 year ago

Seeing a similar issue here, albeit a different project so take this info lightly.

Duplicate class com.stripe.android.uicore.address.AddressRepository_Factory found in modules jetified-identity-20.23.1-runtime (com.stripe:identity:20.23.1) and jetified-link-20.23.1-runtime (com.stripe:link:20.23.1)

As this is a react native project with an Android build and these are the libraries used:

    "@stripe/stripe-identity-react-native": "0.1.2",
    "@stripe/stripe-react-native": "0.23.0",
malua commented 1 year ago

Thank you! I am using a plugin for capacitor and this plugin defines the stripe android sdk itself. So they will have to update.

~I guess that could be your problem as well @algera. The stripe-react-native package will define different versions of the SDKs~

jaynewstrom-stripe commented 1 year ago

It looks like this was a real issue on our end, thanks for reporting. I opened up a PR with the fix. Thanks for the note @algera! It helped me to reproduce the issue.

hsb1007 commented 1 year ago

Hmm for some reason, I am still getting the error after updating the versions

@stripe/stripe-identity-react-native@0.1.7 @stripe/stripe-react-native@0.27.1 stripe@12.4.0

Execution failed for task ':app:checkDebugDuplicateClasses'.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable Duplicate class com.stripe.android.uicore.address.AddressRepository_Factory found in modules jetified-identity-20.24.0-runtime (com.stripe:identity:20.24.0) and jetified-link-20.24.0-runtime (com.stripe:link:20.24.0)