'Error: Program type already present: okhttp3.Address

I have added a new jar file as a module and faced with the above issue. I have already implemented okHttp in my apps gradle file. Seems like the jar file also implementing the same. Any idea how to resolve it?

Edit ** - Posting my apps build gradle file. I have added the library as a project and you can see where I implemented the OkHttp library also

apply plugin: 'com.android.application'


android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.bestdocapp.kiosk_opd"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
    debug {
        debuggable true
        applicationIdSuffix '.debug'
        versionNameSuffix '-DEBUG'


    }

    staging {
        debuggable true
        applicationIdSuffix ".debugStaging"
        versionNameSuffix '-STAGING'
        resValue "string", "app_name", "Kiosk Live"
    }



    release {
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        resValue "string", "app_name", "Kiosk"
        debuggable true
    }
}
dataBinding {
    enabled = true
}

compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
}

}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.wdullaer:materialdatetimepicker:3.6.0'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.wdullaer:materialdatetimepicker:3.6.0'
implementation 'com.brandongogetap:stickyheaders:0.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
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 (project(':library_name'))

}



Solution 1:[1]

I had a very similar problem. When I would build, during the dexing process it would throw this build error:

Program type already present: okhttp3.Address

and in Android Studio where the error occurred it suggested I resolve by going to this page in Google's docs: https://developer.android.com/studio/build/dependencies#duplicate_classes

I had just updated google-services to be this

classpath 'com.google.gms:google-services:4.2.0'

so became suspicious that the conflict resulted because Google's code incorporated Okhttp code. So I completely removed the okhttp .jar file and the supporting okio .jar file., reasoning that if Google was including Okhttp code I didn't need them any more. This completely resolved the problem.

Solution 2:[2]

I have a solution!

in my case.... I checked all my library "/libs" and I found package "okhttp3" in my "ksoap2-android-assembly-3.6.2-jar-with-dependencies"

I remove dir "okhttp3" and it works

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alyoshak
Solution 2 Blazej Kita