重复的zip条目[okhttp-3.10.0.jar:okhttp3 / HttpUrl $ Builder $ ParseResult.class]

时间:2018-04-11 06:10:39

标签: java android retrofit2 proguard okhttp

这里我正在转移第三方库排球进行改造。实际上我在许多项目中都使用过改造,但这是一些独特的问题和解决方案,而不是来自谷歌。

此处app 构建Gradle

apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
    applicationId "com.xyz"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 31
    versionName "7"
    vectorDrawables.useSupportLibrary = true
    multiDexEnabled="true"
}

buildTypes {
    debug {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dataBinding {
    enabled = true
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.googlecode.java-diff-utils:diffutils:1.2.1'
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.android.support:multidex:1.0.0'
}

此处项目构建Gradle

buildscript {
  repositories {
    jcenter()
    google()


}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.1'

}
}

allprojects {
repositories {
    jcenter()
    maven { url 'https://maven.google.com/' }
    maven { url "https://jitpack.io" }
    google()
 }
}

这是一个改进的ApiClient代码:

public class ApiClient implements AppConstants{

public static final String BASE_URL = APP_URL1;
private static Retrofit retrofit = null;

public static Retrofit getClient() {
    OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
            .connectTimeout(1, TimeUnit.MINUTES)
            .readTimeout(1, TimeUnit.MINUTES)
            .writeTimeout(1, TimeUnit.MINUTES)
            .build();
    if (retrofit == null) {
        Gson gson = new GsonBuilder().serializeNulls().create();
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .client(okHttpClient)
                .build();
    }
    return retrofit;
}
}

这是一个错误:

  

引起:java.io.IOException:无法写[E:\ A \ app \ build \ intermediates \ transforms \ proguard \ debug \ 0.jar](无法读取[C:\ Users \ Abhi] .gradle \ caches \ modules-2 \ files-2.1 \ com.squareup.okhttp3 \ okhttp \ 3.10.0 \ 7ef0f1d95bf4c0b3ba30bbae25e0e562b05cf75e \ okhttp-3.10.0.jar(;;;;;; .class)](重复的zip条目[ okhttp-3.10.0.jar:okhttp3 / HttpUrl $生成器$ ParseResult.class]))

2 个答案:

答案 0 :(得分:1)

感谢别人的解决方案,但特别感谢@dpr 这是关于我的问题的解决方案。我们可以在

中看到所有依赖项

选择查看> 工具Windows > Gradle (或点击工具窗口栏中的Gradle)。

展开 AppName > 任务> android并双击androidDependencies 。 Gradle执行任务后,应打开“运行”窗口以显示

我们可以获得所有依赖项:

+--- android.arch.persistence.room:runtime:1.0.0@aar
+--- com.squareup.retrofit2:retrofit:2.4.0@jar
+--- com.android.support:transition:27.1.1@aar
+--- com.android.support:support-fragment:27.1.1@aar
+--- com.android.support:animated-vector-drawable:27.1.1@aar
+--- com.android.support:support-core-ui:27.1.1@aar
+--- com.android.support:support-media-compat:27.1.1@aar
+--- com.android.support:support-core-utils:27.1.1@aar
+--- com.android.support:support-vector-drawable:27.1.1@aar
+--- com.android.support:support-compat:27.1.1@aar
+--- android.arch.lifecycle:runtime:1.1.0@aar
+--- android.arch.persistence.room:common:1.0.0@jar
+--- android.arch.persistence:db-framework:1.0.0@aar
+--- android.arch.persistence:db:1.0.0@aar
+--- android.arch.lifecycle:livedata-core:1.1.0@aar
+--- android.arch.core:runtime:1.1.0@aar
+--- android.arch.core:common:1.1.0@jar
+--- android.arch.lifecycle:common:1.1.0@jar
+--- com.android.support:support-annotations:27.1.1@jar
+--- com.android.support.constraint:constraint-layout-solver:1.0.2@jar
+--- com.squareup.picasso:picasso:2.5.2@jar
+--- com.squareup.okhttp3:okhttp:3.10.0@jar
+--- android.arch.lifecycle:viewmodel:1.1.0@aar
\--- com.squareup.okio:okio:1.14.0@jar

除了gradle之外,它会显示在重复的文件夹中,以便我们可以查找和删除,并且可以解决此问题。

答案 1 :(得分:0)

试试这个

defaultConfig {
    multiDexEnabled true
}