Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

android - Gradle: Execution failed for task ':MyApp:dexDebug'. > Could not call IncrementalTask.taskAction() on task ':MyApp:dexDebug'

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")
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...