如何收缩code - 在DEX 65K法限制 [英] How to shrink code - 65k method limit in dex

查看:203
本文介绍了如何收缩code - 在DEX 65K法限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的Andr​​oid应用程序,它依赖于许多库项目。 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达到!

I looked into both and tried to find out what was causing my method count to go so high. The Google Drive API takes the biggest chunk with the Guava dependency at over 12,000. Total libs for Drive API v2 reach over 23,000!

我的问题我的猜测是,你觉得我该怎么办?我应该删除谷歌驱动器集成为我的应用程序的功能?有没有一种方法来缩小API下来(是的,我使用ProGuard的)?我应该去多DEX路径(这看起来相当痛苦的,与第三方的API特别处理)?

My question I guess is, what do you think I should do? Should I remove Google Drive integration as a feature of my app? Is there a way to shrink the API down (yes, I use proguard)? Should I go the multiple dex route (which looks rather painful, especially dealing with third party APIs)?

推荐答案

它看起来像谷歌终于实现一种解决方法/修复程序超过了DEX文件的65K法的限制。

It looks like Google has finally implementing a workaround/fix for surpassing the 65K method limit of dex files.

关于65K参考限

Android应用(APK)文件包含   在Dalvik的可执行文件的形式执行字节code文件(DEX)   文件,其中包含用于运行你的应用程序编译code。该   Dalvik的可执行的规范限制的方法总数   可在一个单一的DEX文件中引用到65,536,其中包括   Android框架的方法,库方法,并在你自己的方法   code。获得过此限制,您需要配置您的应用程序   建设过程中生成多个DEX文件,被称为multidex   配置。

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

Multidex支持Android 5.0之前的

该平台之前的Andr​​oid 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文件   执行的Andr​​oid设备。有关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法限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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