1

我有一个问题,我无法解决它大约 2 天。我分析了几乎所有有关此错误的问题,但我无法处理。

这是我的树:

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

在这里,我从包括库在内的所有项目中删除了所有 sup 库。我将支持库放在 myOwnLibraryTree 的 libs 文件夹下的一个位置。

在这里,infiniteloopindicator 使用支持库,为此,我将支持库作为 .jar 依赖项添加到无限循环指示符。我也是为 MyApp 做的。没有编译错误。但我明白了,dexDebug 错误。

系统讯息:

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'

这里 settings.gradle

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

这里 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']
    }
  }
}

这里无限循环指示器: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']
        }
    }
}

这里 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
    }
}

这是 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")
}
4

1 回答 1

2

如果您在所有 build.gradle 文件中使用 Maven 样式的 include 语句包含 Support 库,而不是直接链接 jar,事情会更好。要做到这一点:

在您的 SDK 管理器中,确保您已安装“Android 支持存储库”。如果您拥有多个 Android SDK,请确保您已将其安装在正确的 SDK 中——多个 SDK 会导致 Android Studio 经常出现混淆。

在您的所有 build.gradle 文件中,将其放在您的依赖项块中:

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

它应该会自动在 SDK 中查找支持存储库,并且如果在多个地方依赖于该库,Android Gradle 插件将删除该库。

于 2013-11-13T20:10:32.473 回答