首页 > 解决方案 > 错误:程序类型已存在:okhttp3.Address

问题描述

我添加了一个新的 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'))

}

标签: androidretrofitokhttp

解决方案


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

Program type already present: okhttp3.Address

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

我刚刚将 google-services 更新为这样

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

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


推荐阅读