我有一个问题,约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,使用支持lib,为此,我将支持lib添加为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']
}
}
}
这里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']
}
}
}
这里是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")
}
答案 0 :(得分: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插件将对该库进行重复删除。