stripe-android: Duplicate classes

Summary

We are using in our application stripe sdk version 16.1.1 and gradle can’t build project due to duplicated class.

...
Duplicate class org.bouncycastle.x509.util.StreamParsingException found in modules jetified-bcprov-jdk15on-1.57 (org.bouncycastle:bcprov-jdk15on:1.57) and jetified-bcprov-jdk15to18-1.67 (org.bouncycastle:bcprov-jdk15to18:1.67)
...

It looks like a library has changed from bcprov-jdk15on-N.jar to bcprov-jdk15to18-N.jar since version 16.1.0 (bcprov-jdk15on is part of other library that used in our project and could not be removed or updated).

Do you have any solution, ideas, how to avoid current issue and use the latest stripe version.

https://www.bouncycastle.org/latest_releases.html

SDK version

16.1.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 24 (2 by maintainers)

Most upvoted comments

@arslankaleem7229 I use flutter_stripe and was able to get past this error by adding the configuration code within .../android/app/build.gradle

and then pasted the code within android {}

like so:

    android {

    configurations.all {
        c -> c.resolutionStrategy.eachDependency {
            DependencyResolveDetails dependency ->
                println dependency.requested.group
                if (dependency.requested.group == 'org.bouncycastle') {
                    dependency.useTarget 'org.bouncycastle:bcprov-jdk15to18:1.68'
                }
        }
    }

    ...}

Just need to add comment that for my multi modules project it works on slightly another way

configurations.all {
    c -> c.resolutionStrategy.eachDependency {
        DependencyResolveDetails dependency ->
            println dependency.requested.group
             if (dependency.requested.group == 'org.bouncycastle') {
                dependency.useTarget 'org.bouncycastle:bcprov-jdk15to18:1.68'
            }
    }
}

got it done, with

configurations.all {
    c -> c.resolutionStrategy.dependencySubstitution {
        all { DependencySubstitution dependency ->
            if (dependency.requested.group == 'org.bouncycastle') {
                dependency.useTarget 'org.bouncycastle:bcprov-jdk15to18:1.68'
            }
        }
    }
}

project is built and run successfully. Hope everything will work now,

Thank you!

@arslankaleem7229 I use flutter_stripe and was able to get past this error by adding the configuration code within .../android/app/build.gradle

and then pasted the code within android {}

like so:

    android {

    configurations.all {
        c -> c.resolutionStrategy.eachDependency {
            DependencyResolveDetails dependency ->
                println dependency.requested.group
                if (dependency.requested.group == 'org.bouncycastle') {
                    dependency.useTarget 'org.bouncycastle:bcprov-jdk15to18:1.68'
                }
        }
    }

    ...}

Thank you, I was facing this issue. and this worked for me

configurations.all { c -> c.resolutionStrategy.dependencySubstitution { all { DependencySubstitution dependency -> if (dependency.requested.group == ‘org.bouncycastle’) { dependency.useTarget ‘org.bouncycastle:bcprov-jdk15to18:1.68’ } } } }

can you specify the location for this as I am getting same error in flutter_stripe

I also encountered this issue but then experienced crashes in the app when applying the resolution above. It turned out that our application was pulling in more than one module from bouncycastle (bcprov and bcutil) and the resolution replaces both with bcprov.

Making the resolution more specific as below fixed the issue for me

configurations.all {
    c -> c.resolutionStrategy.eachDependency {
        DependencyResolveDetails dependency ->
             if (dependency.requested.group == 'org.bouncycastle' && dependency.requested.name == 'bcprov-jdk15to18') {
                println dependency.requested.module
                dependency.useTarget 'org.bouncycastle:bcprov-jdk15to18:1.69'
                // or ...
                //dependency.useTarget 'org.bouncycastle:bcprov-jdk18on:1.71.1'
            }
    }
}

@lamrak thanks for filing this issue. I’ll investigate and let you know what I find.