所以,我正在尝试将Eclipse ADT项目迁移到Android Studio中。我在app中使用appcompat_v7项目作为库项目。我按照Android开发网站上的说明操作,但我仍然收到此错误:
Error:Execution failed for task :PaWPal:dexDebug.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/godswood/Desktop/adt-bundle-mac-x86_64-20140321/sdk/build-tools/19.1.0/dx --dex --num-threads=4 --output /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/dex/debug /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/classes/debug /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/dependency-cache/debug /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/android-support-v13-7e8441dbe126e0c6ef27b0769fe1a7b51230f497.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/android-support-v4-435683bcc81493f96c2a6911d0f2132f9185a3c8.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/android-support-v7-appcompat-ce23957a305e187b582a49f3d7389771481d29a0.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/classes-0df1e7b55f7a1cf804d7c324e4d8e5350156c424.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/commons-lang3-3.3.2-414f8e20d93f4cd78deef61257feb20e410dc32e.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/joda-time-2.3-e2f8ddd39c18a5b5f810a870e98c34e25539e6e9.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/joda-time-2.3-javadoc-2b8389d156c40d0540abb1e521b4be4ba90b89b7.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/joda-time-2.3-sources-ee3d5e4a6e2aceeeee41f9ab558b6a1430285670.jar /Users/godswood/Desktop/pawpal/PaWPal/build/intermediates/pre-dexed/debug/Parse-1.5.1-b7ce0ef98d2f79d618c5421f63a4845519bd4ced.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
我的Gradle文件看起来像这样:
apply plugin: 'com.android.application'
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':appcompat_v7')
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
如果你有任何想法,我很乐意听到。我知道这里有很多类似的问题,但没有一个解决方案对我有用(悲伤的表情)。
答案 0 :(得分:1)
在Android Studio中,您不需要像在Eclipse中那样将appcompat库包含为库项目。相反,将其添加到 模块 的构建文件的dependencies
块中:
compile 'com.android.support:appcompat-v7:XXXX.+'
其中XXXX
是您的compileSdkVersion
。
另外,我怀疑你的libs文件夹中有一个v4支持库jar的副本(你的类是多重定义的)。如果您像上面一样包含appcompat lib,则根本不需要包含support-v4; appcompat依赖于它,构建系统将做正确的事情。所以继续从你的libs文件夹中删除那个jar。