Gradle: Execution failed for task ':MyApp:dexDebug'. > Could not call IncrementalTask.taskAction() on task ':MyApp:dexDebug'
Asked Answered
B

1

1

I have a problem and i cannot solve it about 2 days. I analysed nearly all questions about this error but i cannot handle it.

Here my tree:

MyAppRoot
-MyApp
     -libs
         -jar4.jar // it does not work, if i don't put here.
-libraries  
     -actionbarsherlock//library project
     -myOwnLibraryTree// project tree
         -libs
              -myjar1.jar
              -android-support-v4.jar
              -myjar2.jar
              -myjar3.jar
     -infiniteloopindicator//library project

Here, i deleted all sup libraries from all projects included library ones. And i put support library at just one place under libs folder in myOwnLibraryTree.

Here, infiniteloopindicator, uses support lib, to do this, i add support lib as a .jar dependency to infiniteloopindicator. And i did it for MyApp,too. There is no compile errors. But i get, dexDebug error.

System message :

Gradle: UNEXPECTED TOP-LEVEL EXCEPTION:
Gradle: java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoStubImpl;
Gradle: at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
Gradle: at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
Gradle: at com.android.dx.command.dexer.Main.processClass(Main.java:490)
Gradle: at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
Gradle: at com.android.dx.command.dexer.Main.access$400(Main.java:67)
Gradle: at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
Gradle: at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
Gradle: at   com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
Gradle: at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
Gradle: at com.android.dx.command.dexer.Main.processOne(Main.java:422)
Gradle: at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
Gradle: at com.android.dx.command.dexer.Main.run(Main.java:209)
Gradle: at com.android.dx.command.dexer.Main.main(Main.java:174)
Gradle: at com.android.dx.command.Main.main(Main.java:91)
Gradle: 1 error; aborting
Compilation completed with 1 error and 0 warnings in 24 sec
1 error
0 warnings
Gradle: Execution failed for task ':MyApp:dexDebug'.
> Could not call IncrementalTask.taskAction() on task ':MyApp:dexDebug'

Here settings.gradle

include ':libraries:infiniteloopindicator',':libraries:actionbarsherlock',':libraries:myOwnLibraryTree', ':MyApp'

Here actionbarsherlock : build.gradle

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.6.+'
}
}


apply plugin: 'android-library'

dependencies {
    compile project(":libraries:myOwnLibraryTree")
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.1'

  sourceSets {
    main {
      manifest.srcFile 'AndroidManifest.xml'
      java.srcDirs = ['src']
      res.srcDirs = ['res']
    }
  }
}

Here infiniteloopindicator : build.gradle

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.6.+'
}
}

apply plugin: 'android-library'

dependencies {

    compile project(":libraries:myOwnLibraryTree")
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.1'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

Here myOwnLibraryTree : build.gradle

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.1'

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }
}

And here is MyApp : build.gradle

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }
}

dependencies {

    compile files('/libs/jar4.jar')
    compile project(":libraries:infiniteloopindicator")
    compile project(":libraries:actionbarsherlock")
    compile project(":libraries:myOwnLibraryTree")
}
Backscratcher answered 13/11, 2013 at 14:38 Comment(0)
H
2

Things will work better if you include Support library using a Maven-style include statement in all your build.gradle files instead of linking the jar directly. To do that:

In your SDK manager, make sure you have the "Android Support Repository" installed. If you have more than one Android SDK, make sure you've installed it in the right one -- multiple SDKs are a cause of frequent Android Studio confusion.

In all your build.gradle files, put this in your dependencies block:

compile 'com.android.support:support-v4:+'

It should automatically look in the SDK for the support repository, and the Android Gradle plugin will dedup the library if it's depended on in multiple places.

Harl answered 13/11, 2013 at 20:10 Comment(4)
Does this problem occur only for support libs ?Backscratcher
I deleted library from my library projects. And i did as you said. But i'm still getting this error.Backscratcher
Looking more closely, your dependencies seem pretty complicated. You have a number of libraries depending on myOwnLibraryTree; is that necessary? Actionbarsherlock, in particular, shouldn't need it. If you can get the dependencies down to the minimum needed set, it will make the problem easier to figure out.Harl
Saved me from "execution failed for task dexdebug" error! Thanks!Tarsuss

© 2022 - 2024 — McMap. All rights reserved.