无法执行 dex:方法 ID 不在 [0, 0xffff] 中:65536 [英] Unable to execute dex: method ID not in [0, 0xffff]: 65536

查看:48
本文介绍了无法执行 dex:方法 ID 不在 [0, 0xffff] 中:65536的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前看过各种版本的 dex 错误,但这个是新的.清洁/重启等无济于事.库项目似乎完好无损,依赖项似乎正确链接.

I have seen various versions of the dex erros before, but this one is new. clean/restart etc won't help. Library projects seems intact and dependency seems to be linked correctly.

Unable to execute dex: method ID not in [0, 0xffff]: 65536
Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536

Cannot merge new index 65950 into a non-jumbo instruction

java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

tl;dr:Google 的官方解决方案终于来了!

tl;dr: Official solution from Google is finally here!

http://developer.android.com/tools/building/multidex.html

只有一个小技巧,您可能需要这样做以防止在执行 dex-ing 时内存不足.

Only one small tip, you will likely need to do this to prevent out of memory when doing dex-ing.

dexOptions {
        javaMaxHeapSize "4g"
}

还有一种巨型模式可以以不太可靠的方式解决此问题:

There's also a jumbo mode that can fix this in a less reliable way:

dexOptions {
        jumboMode true
}

更新:如果你的应用很胖,并且你的主应用中有太多的方法,你可能需要重新组织你的应用

Update: If your app is fat and you have too many methods inside your main app, you may need to re-org your app as per

http://blog.osom.info/2014/12/too-many-methods-in-main-dex.html

推荐答案

更新 3 (11/3/2014)
Google 终于发布了官方说明.

更新 2 (10/31/2014)
适用于 Android 的 Gradle 插件 v0.14.0 添加了对多 dex 的支持.要启用,您只需在 build.gradle 中声明它:

Update 2 (10/31/2014)
Gradle plugin v0.14.0 for Android adds support for multi-dex. To enable, you just have to declare it in build.gradle:

android {
   defaultConfig {
      ...
      multiDexEnabled  true
   }
}

如果您的应用程序支持 Android 5.0 之前的版本(即,如果您的 minSdkVersion 为 20 或以下),您还必须动态修补 应用程序 ClassLoader,因此它会能够从二级 dexes 加载类.幸运的是,有一个可以帮您完成这项工作.将它添加到您的应用程序的依赖项:

If your application supports Android prior to 5.0 (that is, if your minSdkVersion is 20 or below) you also have to dynamically patch the application ClassLoader, so it will be able to load classes from secondary dexes. Fortunately, there's a library that does that for you. Add it to your app's dependencies:

dependencies {
  ...
  compile 'com.android.support:multidex:1.0.0'
} 

需要尽快调用ClassLoader补丁码.MultiDexApplication 类的 documentation 建议了三种方法来做到这一点(选择其中之一,对您来说最方便的一种):

You need to call the ClassLoader patch code as soon as possible. MultiDexApplication class's documentation suggests three ways to do that (pick one of them, one that's most convenient for you):

1 - 将 MultiDexApplication 类声明为 AndroidManifest.xml 中的应用程序:

1 - Declare MultiDexApplication class as the application in your AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

2 - 让您的 Application 类扩展 MultiDexApplication班级:

2 - Have your Application class extend MultiDexApplication class:

public class MyApplication extends MultiDexApplication { .. }

3 - 从您的 Application#attachBaseContext 方法调用 MultiDex#install:

3 - Call MultiDex#install from your Application#attachBaseContext method:

public class MyApplication {
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
        ....
    }
    ....
}

<小时>

更新 1 (10/17/2014):
正如预期的那样,multidex 支持在 Android 支持库的第 21 版中提供.您可以在/sdk/extras/android/support/multidex/library/libs 文件夹中找到 android-support-multidex.jar.


Update 1 (10/17/2014):
As anticipated, multidex support is shipped in revision 21 of Android Support Library. You can find the android-support-multidex.jar in /sdk/extras/android/support/multidex/library/libs folder.

Multi-dex 支持解决了这个问题.dx 1.8 已经允许生成多个 dex 文件.
Android L 将原生支持 multi-dex,支持库的下一个版本将覆盖旧版本回到 API 4.

Multi-dex support solves this problem. dx 1.8 already allows generating several dex files.
Android L will support multi-dex natively, and next revision of support library is going to cover older releases back to API 4.

它在这个 Android Developers Backstage 播客节目中有说明安瓦尔·古卢姆.我已经发布了一份成绩单(以及一般的多-dex 解释)相关部分.

It was stated in this Android Developers Backstage podcast episode by Anwar Ghuloum. I've posted a transcript (and general multi-dex explanation) of the relevant part.

这篇关于无法执行 dex:方法 ID 不在 [0, 0xffff] 中:65536的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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