错误:程序类型已存在:okhttp3.Address

时间:2019-01-08 13:33:24

标签: android retrofit okhttp

我添加了一个新的jar文件作为模块,并面对上述问题。我已经在我的应用gradle文件中实现了okHttp。好像jar文件也实现了同样的功能。知道如何解决吗?

编辑**-发布我的应用程序构建gradle文件。我已经将该库添加为一个项目,您还可以看到在哪里实现了OkHttp库

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'))

}

1 个答案:

答案 0 :(得分:0)

我有一个非常相似的问题。当我进行构建时,在dexing过程中会抛出此构建错误:

Program type already present: okhttp3.Address

,并且在发生错误的Android Studio中,建议我通过转到Google文档中的以下页面来解决此问题:https://developer.android.com/studio/build/dependencies#duplicate_classes

我刚刚将Google服务更新为此

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

因此怀疑是由于Google的代码合并了Okhttp代码而导致冲突。因此,我完全删除了okhttp .jar文件和支持的okio .jar文件。理由是,如果Google包含Okhttp代码,我将不再需要它们。这样就完全解决了问题。