Android dex 加载器无法执行 dex:方法 ID 不在 [0, 0xffff] 中:65536
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25928392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
dex loader unable to execute dex: method ID not in [0, 0xffff]: 65536
提问by user3230564
iam building my application i got this error
我正在构建我的应用程序我收到此错误
Dx warning: Ignoring InnerClasses attribute for an anonymous inner class (com.amazonaws.javax.xml.stream.xerces.util.SecuritySupport12$4) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is notan inner class.
Dx 警告:忽略不带有关联 EnclosureMethod 属性的匿名内部类 (com.amazonaws.javax.xml.stream.xerces.util.SecuritySupport12$4) 的 InnerClasses 属性。此类可能是由未针对现代 .class 文件格式的编译器生成的。推荐的解决方案是从源代码重新编译该类,使用最新的编译器并且不指定任何“-target”类型选项。忽略这个警告的后果是对这个类的反射操作会错误地表明它不是一个内部类。
Dex Loader] 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
Dex Loader] 无法执行 dex: 方法 ID 不在 [0, 0xffff]: 65536 转换为 Dalvik 格式失败: 无法执行 dex: 方法 ID 不在 [0, 0xffff]: 65536
回答by Driss Bounouar
Check the build path -> Java Build Path -> Order and Export tab -> uncheck Android private Librairies.
检查构建路径 -> Java 构建路径 -> 订单和导出选项卡 -> 取消选中 Android 私有库。
If it is still not working, add the following line : dex.force.jumbo=true
to the project.properties
file.
如果它仍然不起作用,请将以下行添加 dex.force.jumbo=true
到project.properties
文件中。
The probable cause is maybe a big sized jar in build path.
可能的原因可能是构建路径中有一个大尺寸的 jar。
Edit :This is deprecated because Eclipse is no longer supported by Google, if you wanna get rid of these annoying problems : use Android Studio and enable Multidex.
编辑:这已被弃用,因为 Google 不再支持 Eclipse,如果您想摆脱这些烦人的问题:使用 Android Studio 并启用 Multidex。
回答by DeltaCap019
Driss Bounouarsolution actually help you in building up your project, but your application may crash at some places after implementing it, I think it actually suppresses the issue at compile time.
Driss Bounouar解决方案实际上可以帮助您构建项目,但是您的应用程序在实施后可能会在某些地方崩溃,我认为它实际上在编译时抑制了问题。
The errors I was getting at console were :-
我在控制台遇到的错误是:-
Dex Loader] 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
[2014-11-08 15:51:58 - MLBPA] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(jnamed) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
[2014-11-08 15:51:58 - MLBPA] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(jnamed) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
[2014-11-08 15:51:58 - MLBPA] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(jnamed) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
[2014-11-08 15:51:59 - MLBPA] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.xbill.DNS.UDPClient) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
According to this Trace I had tried recompiling my all the projects with same and latest compiler but still I was not getting any success.
根据此跟踪,我曾尝试使用相同和最新的编译器重新编译我的所有项目,但仍然没有取得任何成功。
Later on replacing latestgoogle Play serviceswith the older onefixed my issue.
后来更换最新的谷歌Play业务与旧的一个固定我的问题。
I had updated my google play servicesfew hours before and started getting this error there after.
我在几个小时前更新了我的google play 服务,然后开始出现这个错误。
EDIT
编辑
To understand the actual problem you should look at Building Apps with Over 65K MethodsIn our situation it looks like old google Play serviceshad lesser number of methods and hence the project was successfully compiling.
要了解实际问题,您应该查看使用超过 65K 方法构建应用程序在我们的情况下,看起来旧的 google Play 服务的方法数量较少,因此该项目已成功编译。
Brief
简短的
Our whole project is compiled into one dex file which has limit of 65K methods. But now you can enable multidex files in you project. The solution available so far will work only with GRADLE (Android Studio), I haven't found any way to make it work on Eclipse.
我们的整个项目被编译成一个 dex 文件,该文件有 65K 个方法的限制。但是现在您可以在您的项目中启用 multidex 文件。到目前为止可用的解决方案仅适用于 GRADLE (Android Studio),我还没有找到任何方法让它在 Eclipse 上工作。
回答by Ugo Chirico
I just found an alternative to solve this issue on Eclipse when using Google Play Services. Because on Eclipse it seems that there is no way to use multidex as in Android Studio (and Gradle) this seems the only way to work on Eclipse rigth now.
在使用 Google Play 服务时,我刚刚在 Eclipse 上找到了解决此问题的替代方法。因为在 Eclipse 上似乎无法像在 Android Studio(和 Gradle)中那样使用 multidex,这似乎是现在在 Eclipse rigth 上工作的唯一方法。
- go in the google-play-service-lib project
- go in libs
- unzip the file google-play-services.jar
- go in the the unzipped folder and remove all folders that you don't need (i.e. if you need Analytics, you can remove ads, games, maps, wallet, drive, etc.)
- zip again such a folder (that now contains only the needed libraries) together with the MANIFEST folder
- use such new jar with your project.
- 进入 google-play-service-lib 项目
- 进入库
- 解压缩文件 google-play-services.jar
- 进入解压后的文件夹并删除所有您不需要的文件夹(即,如果您需要 Analytics,您可以删除广告、游戏、地图、钱包、驱动器等)
- 再次将这样的文件夹(现在仅包含所需的库)与 MANIFEST 文件夹一起压缩
- 在您的项目中使用这样的新 jar。
回答by Vitaliy A
Expirienced same issue. Problem was in google-play-services_libproject. It includes to many functions. This issue is fixed in 21 and newer versions of google-play-services_lib.
遇到同样的问题。问题出在google-play-services_lib项目中。它包括许多功能。此问题已在 google-play-services_lib 的 21 及更新版本中修复。
To fix multi-dex problem you should remove old lib project completely and use google-play-services_lib_v_21or newer instead.
要解决 multi-dex 问题,您应该完全删除旧的 lib 项目并使用 google-play-services_lib_v_21或更新版本。
For example i used this one: google-play-services.
例如,我使用了这个:google-play-services。
P.S. Also keep in mind that official google play setup docssay:
PS还要记住,官方的google play setup docs说:
You should be referencing a copy of the library that you copied to your development workspace — you should NOT reference the library directly from the Android SDK directory.
您应该引用复制到开发工作区的库的副本——您不应该直接从 Android SDK 目录引用库。
回答by Edo user1419293
I also had recently update the google play libs to version 29 and my app hit the 2^16 limit! I downgraded to version 26 that I knew it worked for me and indeed it has.
我最近也将 google play 库更新到版本 29,我的应用程序达到了 2^16 的限制!我降级到版本 26,我知道它对我有用,而且确实如此。
Developing with Eclipse seems to have become rather unstable now, so it is very advisable to keep track of all the versions of all packages installed!
用 Eclipse 开发现在似乎变得相当不稳定,所以最好跟踪所有安装的包的所有版本!
The solution in the long term is to switch to Android Studio.
从长远来看,解决方案是切换到 Android Studio。
回答by Srinivas
You get this error mainly because there is a limitation on dalvik executable files and apparently the limit is 65536 which is 2^16.
您收到此错误主要是因为 dalvik 可执行文件存在限制,显然限制为 65536,即 2^16。
You have to enable multi-dex configuration for your android application. To enable multi-dex, follow these steps:
您必须为您的 android 应用程序启用多 dex 配置。要启用多 dex,请按照下列步骤操作:
Edit your build.gradle file of your main module (app)
android { defaultConfig { ... multiDexEnabled true } } dependencies { ... compile 'com.android.support:multidex:1.0.1' }
Tell your application class to handle these changes.
You can edit your custom application class to enable multi-dex support.
public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } }
OR
public class MyApplication extends MultiDexApplication{ }
OR
Edit your AndroidManifest.xml file to apply your changes to the application tag
<?xml version="1.0" encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application ... android:name="android.support.multidex.MultiDexApplication"> ... </application>
编辑主模块(应用程序)的 build.gradle 文件
android { defaultConfig { ... multiDexEnabled true } } dependencies { ... compile 'com.android.support:multidex:1.0.1' }
告诉您的应用程序类来处理这些更改。
您可以编辑自定义应用程序类以启用多 dex 支持。
public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } }
或者
public class MyApplication extends MultiDexApplication{ }
或者
编辑您的 AndroidManifest.xml 文件以将您的更改应用到应用程序标记
<?xml version="1.0" encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application ... android:name="android.support.multidex.MultiDexApplication"> ... </application>
There are limitation below API Level 14 and below. Your app may not compile or run below API level 14. While compiling you can get OutOfMemory exception. To resolve this, add the following to build.gradle
API 级别 14 及以下有限制。您的应用程序可能无法在 API 级别 14 以下编译或运行。编译时您可能会遇到 OutOfMemory 异常。要解决此问题,请将以下内容添加到 build.gradle
dexOptions {
jumboMode true
javaMaxHeapSize "4g"
}