使用Android Gradle的IntelliJ中出现意外的顶级异常

使用Android Gradle的IntelliJ中出现意外的顶级异常,android,intellij-idea,gradle,Android,Intellij Idea,Gradle,首先,我是IntelliJ和Gradle的新人 我正在将一个Android Eclipse项目迁移到IntelliJ,但我有一些问题 我知道在一个普通的Eclipse项目中,库是手动导入的,这些依赖项必须以相同的方式导入,但是当从gradle导入时,依赖项会像maven一样自动导入 目前,我有下一个配置 在我的项目中: 渐变配置: apply plugin: 'android' buildscript { repositories { mavenCentral()

首先,我是IntelliJ和Gradle的新人

我正在将一个Android Eclipse项目迁移到IntelliJ,但我有一些问题

我知道在一个普通的Eclipse项目中,库是手动导入的,这些依赖项必须以相同的方式导入,但是当从gradle导入时,依赖项会像maven一样自动导入

目前,我有下一个配置

在我的项目中:

渐变配置:

apply plugin: 'android'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ('com.google.android.gms:play-services:5.2.+')
    compile ('mobi.parchment:parchment:1.6.7@aar')
}

android {
    compileSdkVersion "Google Inc.:Google APIs:19"
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 13
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}
在libs文件夹中(Eclipse项目依赖项的旧继承):

所有这些库都是从模块依赖项面板添加到项目中的“编译”范围

在我的gradle里,正如你在上面看到的

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ('com.google.android.gms:play-services:5.2.+')
    compile ('mobi.parchment:parchment:1.6.7@aar')
}
我可以看到播放服务和羊皮纸库也从模块依赖项面板中添加

然后,我在终端中使用命令“gradle-q dependencies”查找库的不兼容性

+--- com.google.android.gms:play-services:5.2.+ -> 5.2.08
|    \--- com.android.support:support-v4:19.1.0
\--- mobi.parchment:parchment:1.6.7
正如我之前从项目中删除了默认库支持-v4一样,我知道这一切都是正常的

但是,当我要在移动设备上运行我的项目时,我会遇到下一个错误:

错误:梯度:任务“:projectname:dexDebug”的执行失败

com.android.ide.common.internal.LoggedErrorException:无法运行命令:


Dalvik VM每个dex文件最多可以有65536个方法

试试这个

您可以将程序的一部分划分为多个辅助dex文件,并在运行时加载它们


也请检查此项

非常感谢,我不知道此问题,而您已为我指明了正确的方向。例如,将db4o的所有库替换为db4o核心就足以解决这个问题。但是,在这个未来的问题之前,您知道如何使用gradle而不是ant进行修复吗?将multiDexEnabled true添加到build.gradle文件的defaultConfig中
+--- com.google.android.gms:play-services:5.2.+ -> 5.2.08
|    \--- com.android.support:support-v4:19.1.0
\--- mobi.parchment:parchment:1.6.7
\path\Android\sdk\build-tools\19.0.0\dx.bat --dex --output
\my\path\project\subproject\build\dex\debug \my\path\project\subproject\build\classes\debug 
\my\path\project\subproject\build\dependency-cache\debug 
\my\path\project\subproject\build\pre-dexed\debug\asmack-android-9-0.8.9-658505d39f87eb574ca22fd661701c368ba56c43.jar 
\my\path\project\subproject\build\pre-dexed\debug\classes-240d6f35592e28516cbacf563e5cf7d397c47597.jar
\my\path\project\subproject\build\pre-dexed\debug\classes-5396eb2d8c60977d5c7d783ccb88f7ee9f9ac0a5.jar 
\my\path\project\subproject\build\pre-dexed\debug\db4o-8.0.249.16098-all-java5-f4e9589ca8c62f8f04674804913667eaa24098e1.jar 
\my\path\project\subproject\build\pre-dexed\debug\jackson-annotations-2.2.2-c64587b3c9ef74b3bc31853dd03c4298b0d1c8e7.jar 
\my\path\project\subproject\build\pre-dexed\debug\jackson-core-2.2.2-0680a2e78b72cbcf4363912327628ec2dc9d9e8c.jar 
\my\path\project\subproject\build\pre-dexed\debug\jackson-databind-2.2.2-a3024e8795a241f49dd299408ad4afcc1550bc6f.jar 
\my\path\project\subproject\build\pre-dexed\debug\prime-0.6.1-235f838c02be4726326732322228c79267281ab3.jar 
\my\path\project\subproject\build\pre-dexed\debug\spring-android-auth-1.0.1.RELEASE-23860c8c94cb82ac5a3173256145e410145bf99a.jar 
\my\path\project\subproject\build\pre-dexed\debug\spring-android-core-1.0.1.RELEASE-18a42ae43d0082129e8fa1dbd9a76d7665ec6c44.jar 
\my\path\project\subproject\build\pre-dexed\debug\spring-android-rest-template-1.0.1.RELEASE-d7e59e9cc594e05c76438d8db3ed6ec4dafe5f04.jar 
\my\path\project\subproject\build\pre-dexed\debug\support-v4-19.1.0-463587e3dcdb43547b185cddcf5e895c619b1cbc.jar
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
        at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:500)
        at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:275)
        at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:489)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:166)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
        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)