Younss Drhouj
Younss Drhouj

Reputation: 51

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug' android studio

I create a game on buildbox I export the project but I can't start the game on android studio My problem is that I can't run the application or produce an apk file

someone can help me please.

The error

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. java.io.IOException: Can't write [C:\Users\youne\Desktop\android2\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\youne.gradle\caches\transforms-1\files-1.1\support-core-ui-25.2.0.aar\9adfc8649fc899fbc5e371e8bc1c399a\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/v4/view/ViewPager$2.class]))

I am using

Android Studio 3.0

Java version: Java(TM) SE Runtime Environment (build 1.8.0_73-b02).

Gradle Version: com.android.tools.build:gradle:4.1

And i have Multidex enabled

In my app build.gradle file:

android {
  compileSdkVersion 27
  buildToolsVersion '27.0.1'

  defaultConfig {
    applicationId "com.drh.bird"
    minSdkVersion 14
    targetSdkVersion 23
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
    compileOptions.encoding = 'ISO-8859-1'
    multiDexEnabled = true

    ndk {
      moduleName "player_shared"
    }
  }
  android {
    useLibrary 'org.apache.http.legacy'
  }
  sourceSets {
    main {
      jni.srcDirs = []
    }
  }

  buildTypes {}
  android {
    defaultConfig {
      multiDexEnabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
  }
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
  compile 'com.google.android.gms:play-services:+'
  compile files('libs/dagger-1.2.2.jar')
  compile files('libs/javax.inject-1.jar')
  compile files('libs/nineoldandroids-2.4.0.jar')
  compile files('libs/support-v4-19.0.1.jar')
}

Upvotes: 5

Views: 9605

Answers (3)

ישו אוהב אותך
ישו אוהב אותך

Reputation: 29783

This is because your support library is conflicted. You should always use the same version code for compileSdkVersion, buildToolsVersion, targetSdkVersion, and support library.

You should not using a jar file with

compile files('libs/support-v4-19.0.1.jar')

Instead you need to use support library that matching with your compileSdkVersion like this:

implementation 'com.android.support:support-v4:27.1.0'

You also need to use an exact version of play service and make sure you are using specific individual API. Not like this:

compile 'com.google.android.gms:play-services:+'

But something like this:

// if you're using only ads
implementation 'com.google.android.gms:play-services-ads:12.0.0'

this will make your method count small and then you can remove the multidex.

In the end, your build.gradle should be something like this:

android {
  compileSdkVersion 27
  buildToolsVersion '27.0.1'

  defaultConfig {
    applicationId "com.drh.bird"
    minSdkVersion 14
    targetSdkVersion 27
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
    compileOptions.encoding = 'ISO-8859-1'
    //multiDexEnabled = true

    ndk {
      moduleName "player_shared"
    }
  }
  android {
    useLibrary 'org.apache.http.legacy'
  }
  sourceSets {
    main {
      jni.srcDirs = []
    }
  }

  buildTypes {}
  android {
    defaultConfig {
      //multiDexEnabled true
    }
  }
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
  }

  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
  }
}

dependencies {
  //compile 'com.android.support:multidex:1.0.1'
  implementation 'com.google.android.gms:play-services:play-services-ads:12.0.0'
  implementation 'com.android.support:support-v4:27.1.0'

  compile files('libs/dagger-1.2.2.jar')
  compile files('libs/javax.inject-1.jar')
  compile files('libs/nineoldandroids-2.4.0.jar')
  //compile files('libs/support-v4-19.0.1.jar')
}

Upvotes: 0

Ashwin H
Ashwin H

Reputation: 723

implementation 'com.android.support:appcompat-v7:27.1.0'
 implementation 'com.android.support:design:27.1.0'
    implementation 'com.android.support:support-v4:27.1.0'
 implementation 'com.android.support:recyclerview-v7:27.1.0'

update your all support library to 27.1.0 like above and remove duplicates

Upvotes: 8

DeKaNszn
DeKaNszn

Reputation: 2730

You are trying to use compile files('libs/support-v4-19.0.1.jar') with compileSdkVersion 27. But support library should have major version equal to compileSdkVersion

Use implementation "com.android.support:support-v4:27.0.1" instead it

Also, never use + in dependencies version. You may get some problems, when dependency has updated

Upvotes: 1

Related Questions