gpt4 book ai didi

java - ADT 到 Android Studio 意外顶级异常

转载 作者:行者123 更新时间:2023-11-30 11:16:39 24 4
gpt4 key购买 nike

因此,我正在尝试将我的 Eclipse ADT 项目迁移到 Android Studio。我将 appcompat_v7 项目用作 eclipse 中的库项目。我按照 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')
}
}

如果您有任何想法,我很想听听。我知道这里有很多类似的问题,但没有一个解决方案对我有用(悲伤的脸)。

最佳答案

在 Android Studio 中,您不需要像在 Eclipse 中那样将 appcompat 库作为库项目包含在内。相反,将其添加到 模块 构建文件的 dependencies block 中:

 compile 'com.android.support:appcompat-v7:XXXX.+'

XXXX 是您的 compileSdkVersion

此外,我怀疑您的 libs 文件夹中有 v4 支持库 jar 的副本(您在该文件夹中获得了多重定义的类)。如果像上面那样包含 appcompat 库,则根本不需要包含 support-v4; appcompat 依赖于它,构建系统将做正确的事情。因此,继续并从您的 libs 文件夹中删除该 jar。

关于java - ADT 到 Android Studio 意外顶级异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24768869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com