意外的顶级例外的IntelliJ与Android摇篮 [英] UNEXPECTED TOP-LEVEL EXCEPTION in IntelliJ with Android Gradle

查看:224
本文介绍了意外的顶级例外的IntelliJ与Android摇篮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firtly,我用新的IntelliJ和摇篮。

我移植一个Android的Eclipse项目的IntelliJ,但我有一些问题。

我知道在一个共同的Eclipse项目,库手动导入,这些依赖必须以同样的方式进口,但是当从依赖的gradle进口的是进口自动行家一样做。

目前,我旁边的配置。

在我的项目:

摇篮配置:

 应用插件:'机器人'buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径'com.android.tools.build:gradle:0.9.+
    }
}库{
    mavenCentral()
}依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
    编译('com.google.android.gms:播放服务:5.2 +。')
    编译('mobi.parchment:羊皮纸:1.6.7@aar')
}安卓{
    compileSdkVersion谷歌Inc.:Google的API:19
    buildToolsVersion19.0.0    defaultConfig {
        13的minSdkVersion
        targetSdkVersion 19
        版本code 1
        的versionName1.0
    }
    buildTypes {
        发布 {
            runProguard假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard的-rules.txt
        }
    }    packagingOptions {
        排除META-INF / DEPENDENCIES.txt
        排除META-INF / LICENSE.TXT
        排除META-INF / NOTICE.txt
        排除META-INF /注意事项
        排除META-INF / LICENSE
        排除META-INF /相关内容
        排除META-INF / notice.txt
        排除META-INF / LICENSE.TXT
        排除META-INF / dependencies.txt
        排除META-INF / LGPL2.1
    }
}

在libs文件夹中(Eclipse项目依赖的旧继承):

  -asmack-Android的9-0.8.9.jar
-db4o-8.0.249.16098-全java5.jar
-jackson的注解 - 2.2.2.jar
-jackson核心-2.2.2.jar
-jackson-数据绑定-2.2.2.jar
-prime-0.6.1.jar
-spring-Android的AUTH-1.0.1.RELEASE.jar
-spring-Android的核心1.0.1.RELEASE.jar
-spring-Android的休息-模板1.0.1.RELEASE.jar

所有这些库都添加了编译的范围从模块依赖面板项目。

在我gradle这个,因为你可以看到上面。

  {相关性
    编译文件树(导演:'库',包括:['的* .jar'])
    编译('com.google.android.gms:播放服务:5.2 +。')
    编译('mobi.parchment:羊皮纸:1.6.7@aar')
}

我可以看到播放服务和羊皮纸库将从模块依赖面板添加太过。

然后,我期待在终端使用命令-q的Gradle依赖库不兼容。

  + --- com.google.android.gms:发挥服务:5.2 +  - 方式> 08年2月5日
| \\ --- com.android.support:support-v4:19.1.0
\\ --- mobi.parchment:羊皮纸:1.6.7

当我previously删除默认库从项目支持-V4,据我所知,所有的这是正常的。

但是,当我要运行我的项目的移动设备,我得到下一个错误:

错误:摇篮:执行失败的任务:项目名称:dexDebug。


  

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


  \\路径\\ Android的\\ SDK \\构建工具\\ 19.0.0 \\ dx.bat --dex --output
\\我\\路径\\项目\\子项目\\编译\\ DEX \\调试\\我\\路径\\项目\\子项目\\编译\\类\\调试
\\我\\路径\\项目\\子项目\\ build中\\依赖缓存\\调试
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\asmack-android-9-0.8.9-658505d39f87eb574ca22fd661701c368ba56c43.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\classes-240d6f35592e28516cbacf563e5cf7d397c47597.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\classes-5396eb2d8c60977d5c7d783ccb88f7ee9f9ac0a5.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\db4o-8.0.249.16098-all-java5-f4e9589ca8c62f8f04674804913667eaa24098e1.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\jackson-annotations-2.2.2-c64587b3c9ef74b3bc31853dd03c4298b0d1c8e7.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\jackson-core-2.2.2-0680a2e78b72cbcf4363912327628ec2dc9d9e8c.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\jackson-databind-2.2.2-a3024e8795a241f49dd299408ad4afcc1550bc6f.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\prime-0.6.1-235f838c02be4726326732322228c79267281ab3.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\spring-android-auth-1.0.1.RELEASE-23860c8c94cb82ac5a3173256145e410145bf99a.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\spring-android-core-1.0.1.RELEASE-18a42ae43d0082129e8fa1dbd9a76d7665ec6c44.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\spring-android-rest-template-1.0.1.RELEASE-d7e59e9cc594e05c76438d8db3ed6ec4dafe5f04.jar
\\my\\path\\project\\subproject\\build\\$p$p-dexed\\debug\\support-v4-19.1.0-463587e3dcdb43547b185cddcf5e895c619b1cbc.jar
错误code:
    2
输出:
    意外的顶级例外:
    java.lang.IllegalArgumentException异常:不是方法ID [0,0xFFFF的]:65536
        在com.android.dx.merge.DexMerger $ 6.updateIndex(DexMerger.java:500)
        在com.android.dx.merge.DexMerger $ IdMerger.mergeSorted(DexMerger.java:275)
        在com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:489)
        在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:166)
        在com.android.dx.merge.DexMerger.merge(DexMerger.java:187)
        在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
        在com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
        在com.android.dx.command.dexer.Main.run(Main.java:230)
        在com.android.dx.command.dexer.Main.main(Main.java:199)
        在com.android.dx.command.Main.main(Main.java:103)


解决方案

Dalvik虚拟机可以有最多不超过DEX文件65536方法

试试这个的http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html

你可以分区计划的一部分进入多个辅助DEX文件,并在运行时加载它们。

检查这也是<一个href=\"http://stackoverflow.com/a/18069006/3020568\">http://stackoverflow.com/a/18069006/3020568

Firtly, I am new with IntelliJ and Gradle.

I am migrating an Android Eclipse project to IntelliJ, but I have some problems.

I know in a common Eclipse project, libraries are imported manually and those dependencies must to be imported in the same way, but when are imported from gradle dependencies are imported automatically like maven do.

Currently, I have next configuration.

In my project:

Gradle config:

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'
    }
}

In libs folder (old inheritance of Eclipse project dependencies):

-asmack-android-9-0.8.9.jar
-db4o-8.0.249.16098-all-java5.jar
-jackson-annotations-2.2.2.jar
-jackson-core-2.2.2.jar
-jackson-databind-2.2.2.jar
-prime-0.6.1.jar
-spring-android-auth-1.0.1.RELEASE.jar
-spring-android-core-1.0.1.RELEASE.jar
-spring-android-rest-template-1.0.1.RELEASE.jar

All those libraries are added with "compile" scope to the project from Module Dependencies Panel.

in my gradle, as you could see above.

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

I can see play-services and parchment libraries are added too from the Module Dependencies Panel too.

Then, I look for libraries incompatibilities using command "gradle -q dependencies" in the terminal.

+--- 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

As I previously removed default library support-v4 from project, I understand that all it's alright.

But, When I going to run my project to mobile device, I get next error:

Error:Gradle: Execution failed for task ':projectname:dexDebug'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command:

\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)

解决方案

Dalvik VM can have a maximum of 65536 methods per dex file

Try this http://android-developers.blogspot.co.il/2011/07/custom-class-loading-in-dalvik.html

"You can partition part of the program into multiple secondary dex files, and load them at runtime."

Check this also http://stackoverflow.com/a/18069006/3020568

这篇关于意外的顶级例外的IntelliJ与Android摇篮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆