我剛用新的Gradle構建系統更新了我的項目。已添加的庫:Gradle Build
嘗試了幾次後,我總是以同樣的問題失敗。
我有一個項目,有許多子庫項目。那些使用support-library-v4,我的主項目也使用它。 經過一番搜索我發現我不得不使用maven鏈接:
compile 'com.android.support:support-v4:13.0.0'
我添加了這一點(左爲Eclipse兼容性libs文件夾的jar) ,但仍然得到了同樣的錯誤
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompatHoneycomb;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
at com.android.dx.command.dexer.Main.processClass(Main.java:490)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
at com.android.dx.command.dexer.Main.access$400(Main.java:67)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
at com.android.dx.command.dexer.Main.processOne(Main.java:422)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
at com.android.dx.command.dexer.Main.run(Main.java:209)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
我甚至試圖刪除libs文件夾中的/那些庫,但沒有運氣
我使用gradle這個最新版本的「classpath 'com.android.tools.build:gradle:0.5.4'
」 但沒有運氣。
我希望有人有更好的主意?
這裏是我的構建腳本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.4'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
dependencies {
repositories {
mavenCentral()
}
compile project(':HoloGraphLibrary')
compile project(':CardsUI')
compile project(':Caldroid')
compile project(':BetterPickers')
compile project(':Crouton')
compile project(':ShowcaseView')
compile project(':AboutLibraries')
compile project(':StyledDialogs')
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:support-v4:13.0.0'
compile 'joda-time:joda-time:2.2'
compile files('libs/ActiveAndroid-3.3.jar')
compile files('libs/crashlytics.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
,這裏是我的庫之一的一個構建腳本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.4'
}
}
apply plugin: 'android-library'
dependencies {
// compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:13.0.0'
compile 'joda-time:joda-time:2.2'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
我建議你也確保你不是在一些項目中不小心引用了「com.android.support:support-v4:13.0.0」,而是「com.android.support:support-v13:13.0」。 0「。有時候很容易讓v13和r13的命名混合在一起 – Greg
@Greg,這應該不成問題。 -v13依賴-v4而不是嵌入-v4(就像非神器版本一樣),所以它不應該觸發重複的類。 –
謝謝,我不知道! – Greg