0

Here I am transfering third party library volley to retrofit.Actually I had used retrofit in many projects,But this is some unique problem and solution not getting from google also.

Here app Build 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'
}

Here Project Build 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()
 }
}

Here is a retrofit ApiClient Code:

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;
}
}

Here is an error:

Caused by: java.io.IOException: Can't write [E:\A\app\build\intermediates\transforms\proguard\debug\0.jar] (Can't read [C:\Users\Abhi.gradle\caches\modules-2\files-2.1\com.squareup.okhttp3\okhttp\3.10.0\7ef0f1d95bf4c0b3ba30bbae25e0e562b05cf75e\okhttp-3.10.0.jar(;;;;;;.class)] (Duplicate zip entry [okhttp-3.10.0.jar:okhttp3/HttpUrl$Builder$ParseResult.class]))

  • Did you added **multiDexEnabled=true** ? – Jay Rathod Apr 11 '18 at 06:12
  • yeah I had added multiDexEnabled=true – Abhishek Bardolia Apr 11 '18 at 06:13
  • actually I had modified and just showed here few gradle dependencies. – Abhishek Bardolia Apr 11 '18 at 06:14
  • Maybe try to delete the gradle cache at `C:\Users\Abhi.gradle\caches\modules-2\files-2.1` gradle will download all needed jars the next time you build your project again. This way you can rule out any issues with your locally stored copies of the needed dependencies. – dpr Apr 11 '18 at 08:05
  • @dpr :I tried to delete files-2.1 still same issue. – Abhishek Bardolia Apr 13 '18 at 05:16
  • just see I had updated my Question and do give me solution. – Abhishek Bardolia Apr 13 '18 at 05:45
  • @AbhishekBardolia please add the output of `gradlew dependencies` to your question. The problem is probably that there are two different versions of okhttp on the classpath. – dpr Apr 13 '18 at 07:36
  • @dpr See gradlew dependencies added in question. – Abhishek Bardolia Apr 13 '18 at 07:44
  • @AbhishekBardolia my fault for android the command is slightly different. It's `gradlew app:dependencies` where `app` is your project module. See https://stackoverflow.com/questions/21645071/using-gradle-to-find-dependency-tree – dpr Apr 13 '18 at 07:54
  • @dpr Can you please elaborate seen your link...I guess I am new in this can you pl elaborate?? – Abhishek Bardolia Apr 13 '18 at 09:29
  • 1
    See [here](https://developer.android.com/studio/build/dependencies.html#view-dependency-tree) perhaps? The output I requested is not from `gradlew dependencies` but from `gradlew :dependencies` where `` is the name of your application project. – dpr Apr 13 '18 at 09:35
  • Thank you sir@dpr for this solution it is best so far.I got it – Abhishek Bardolia Apr 13 '18 at 10:19
  • This was actually not thought to solve your problem. Please add the output of `gradlew :dependencies` to the question. – dpr Apr 13 '18 at 19:03
  • yeah you are right....but by your way i got a solution i was having two okhttp and other was in one library,I had deleted and now the problem is solve. – Abhishek Bardolia Apr 14 '18 at 04:34
  • Maybe you could post your solution as answer to your own question. This way others will be able to see that this question was solved and may benefit from your answer. – dpr Apr 14 '18 at 07:11

2 Answers2

1

Appreciate others for solution but special thanks to @dpr Here is a solution regarding my problem.We can see all dependencies in

Select View > Tool Windows > Gradle (or click Gradle in the tool windows bar).

Expand AppName > Tasks > android and double-click androidDependencies. After Gradle executes the task, the Run window should open to display

We can get all dependencies:

+--- 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

Apart from gradle it will show you in folder which is duplicate so we can find and delete and can solve this.

0

Try this

defaultConfig {
    multiDexEnabled true
}
ColdFire
  • 6,764
  • 6
  • 35
  • 51