问题描述
我有一个相当大的Android应用程序,它依赖于许多库项目。 Android的编译器有每个.dex文件65536方法的限制,我超过了这个数字。
I have a rather large Android app that relies on many library projects. The Android compiler has a limitation of 65536 methods per .dex file and I am surpassing that number.
基本上有两条路可以选择(至少我所知道的),当你打的方法限制。
There are basically two paths you can choose (at least that I know of) when you hit the method limit.
1)收缩你的code
1) Shrink your code
2)建立多个DEX文件(看到这个博客帖子)
2) Build multiple dex files (see this blog post)
我看着这两个,并试图找出是什么造成我的方法算去那么高。在谷歌驱动器API采用与番石榴依赖最大的一块为12000。总库为23000驱动API V2达到!
推荐答案
它看起来像谷歌终于实现一种解决方法/修复程序超过了DEX文件的65K法的限制。
该平台之前的Android 5.0版本使用了Dalvik的运行时间 执行程序code。默认情况下,Dalvik的限制应用程序到一个 每个APK classes.dex字节code文件。为了解决这个问题 限制,您可以使用 multidex支持库,成为 你的应用程序的主DEX文件的一部分,然后管理访问 另外DEX文件和它们所包含的code。
Versions of the platform prior to Android 5.0 use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can use the multidex support library, which becomes part of the primary DEX file of your app and then manages access to the additional DEX files and the code they contain.
Multidex支持为Android 5.0及更高版本
Android的5.0和更高版本使用一个运行时被称为艺术,本机 支持从应用程序APK文件加载多个DEX文件。艺术 执行pre-编译的应用程序安装时它扫描 类(.. N).dex文件,并编译成一个单一的.oat文件 执行的Android设备。有关Android的更多信息 5.0运行时,见介绍ART 。
Android 5.0 and higher uses a runtime called ART which natively supports loading multiple dex files from application APK files. ART performs pre-compilation at application install time which scans for classes(..N).dex files and compiles them into a single .oat file for execution by the Android device. For more information on the Android 5.0 runtime, see Introducing ART.
请参阅:建筑应用服务超过65K方法
Multidex支持库
该库提供用于构建支持 应用程序使用多个Dalvik的可执行文件(DEX)文件。引用应用程序 超过65536的方法都需要使用multidex配置。 有关使用multidex的更多信息,请参见构建应用程序与过 65K方法。
This library provides support for building apps with multiple Dalvik Executable (DEX) files. Apps that reference more than 65536 methods are required to use multidex configurations. For more information about using multidex, see Building Apps with Over 65K Methods.
该库位于/演员/安卓/支持/ multidex / 目录中下载Android支持库之后。该 库不包含用户界面资源。把它列入 您的应用程序项目,请按照添加库的指令 没有资源。
This library is located in the /extras/android/support/multidex/ directory after you download the Android Support Libraries. The library does not contain user interface resources. To include it in your application project, follow the instructions for Adding libraries without resources.
在摇篮构建脚本的依赖标识符这个库是作为 如下:
The Gradle build script dependency identifier for this library is as follows:
com.android.support:multidex:1.0.+这种依赖性符号指定 发行版1.0.0或更高版本。
com.android.support:multidex:1.0.+ This dependency notation specifies the release version 1.0.0 or higher.
您还是应该避免通过积极利用ProGuard,并将审核您的依赖击中65K法的限制。
You should still avoid hitting the 65K method limit by actively using proguard and reviewing your dependencies.
这篇关于如何收缩code - 在DEX 65K法限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!