2

I have been working on a project and recently added a lot of libraries. Then when I try to run the project, I am facing following error

Program type already present: org.apache.commons.codec.Decoder

and I do not know to fix it. I searched many times but could not found same example with me.

Following is the app Gradle dependency list:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.0.0'
    implementation "com.android.support:support-v4:26.0.0"
    implementation 'com.android.support:design:26.0.0'
    implementation project(path: ':downloader_library')

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.nineoldandroids:library:2.4.0'

//    implementation 'com.javacodegeeks:slf4jconfig-javalogging:+'
    implementation 'org.slf4j:slf4j-api:1.7.25'
    implementation 'org.apache.commons:commons-compress:1.12'
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'org.apache.commons') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '1.12'
            }
        }
        if (details.requested.group == 'com.android.support'
                && !details.requested.name.contains('multidex') ) {
            details.useVersion "26.0.0"
        }
    }
}

I have tried a lot of solutions like changing library version and adding resolution-strategy as mentioned in above grade code but still no solution.

Can you guys help me to fix the problem?

Thank you

Rohit Gupta
  • 1,368
  • 1
  • 14
  • 30
  • 1
    maybe this answer can help you to identify the library in conflict: https://stackoverflow.com/a/49767860/6899896 – M.Ricciuti Oct 30 '18 at 13:40
  • have you already solved this? I have the same problem, I got this using the dependency 'org.apache.olingo:odata-client-core:4.5.0' – Raniel Quirante Dec 26 '18 at 14:28
  • okay just an updat: I managed to do this by going to the link that @M.Ricciuti posted here, and tried the gradlew app:dependencies, then excluded the sub-dependency from the main dependency that I used. – Raniel Quirante Dec 26 '18 at 14:38
  • So, basically no more error like yours is present on my side :) – Raniel Quirante Dec 26 '18 at 14:38
  • I was facing the same error, but I had different dependencies. This is how I solved using the link previously provided: `implementation('org.apache.poi:poi-scratchpad:3.9') { exclude module: 'commons-codec' } implementation('org.apache.poi:poi-ooxml:3.9') { exclude module: 'commons-codec' } implementation('org.apache.poi:poi:3.9') { exclude module: 'commons-codec' }` – lasnow Mar 20 '19 at 18:02

1 Answers1

0

This problem is occurred from a naming conflict. In this case org.apache.commons.codec.Decoder is present in multiple libraries. I also get this when I include the Jwt auth0 library. What I did to over come is

Implementation('com.auth0:java-jwt:3.8.0'){
  exclude module: 'commons-codec'
}

What you have to do is exclude the commons-codec module when you include the new dependency.

ebo
  • 2,717
  • 1
  • 27
  • 22
Neshan Manilka
  • 64
  • 1
  • 2
  • 10