- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有一个相当大的 Android 应用程序,它依赖于许多库项目。 Android 编译器对每个 .dex 文件有 65536 个方法的限制,我已经超过了这个数字。
当你达到方法限制时,基本上有两条路径可以选择(至少我知道)。
1) 缩小代码
2) 构建多个dex文件(see this blog post)
我查看了两者并试图找出导致我的方法计数如此之高的原因。 Google Drive API 占据了 Guava 依赖项的最大部分,超过 12,000 个。 Drive API v2 的库总数超过 23,000 个!
我想我的问题是,你认为我应该怎么做?我应该删除 Google Drive 集成作为我的应用程序的一项功能吗?有没有办法缩小 API(是的,我使用 proguard)?我应该走多 dex 路线吗(这看起来相当痛苦,尤其是处理第三方 API)?
最佳答案
看起来 Google 终于实现了解决方法/修复超过 dex 文件的 65K 方法限制。
About the 65K Reference Limit
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 support prior to Android 5.0
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 support for Android 5.0 and higher
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.
见:Building Apps with Over 65K Methods
Multidex Support Library
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.
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.+ This dependency notation specifies the release version 1.0.0 or higher.
您仍应通过积极使用 proguard 并检查您的依赖项来避免达到 65K 方法限制。
关于android - 如何收缩代码 - dex 中的 65k 方法限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15471772/
Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files defi
我试图在 avd 中运行我的应用程序,但是当我选择运行 gradle 时出现异常: Error:Error converting bytecode to dex: Cause: com.android
当我提取一个文件 aab 时出现这个错误: Invalid dex file indices, expecting file 'classes٢.dex' but found 'classes2.de
我有一个 ionic 项目。它已成功构建并在我的 android 手机中运行。突然有一天,当我运行命令“ionic cordova run android”时,我得到如下构建错误: Dex: Erro
这个问题在这里已经有了答案: Unable to execute dex: Multiple dex files define (31 个回答) 4年前关闭。 我更新了 android studio
从过去 3 天开始,我遇到了这个错误,并且已经尽了我所能。任何人都可以帮我纠正它。我正在使用 Android 3.0,我的 sdk 和 Google Play 服务已更新,并且我已将 multiDex
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.nnroh.debtmanager, PI
好的,现在我真的被困在这里了。我不知道该做什么,去哪里或任何事情! 我一直在尝试卸载、重新安装 SDK 和 Eclipse 版本,尝试用谷歌搜索出来,但是 nu-uh... 什么都没有!!! 我可以在
怎么了?为什么我有这个问题? Unable to execute dex: Multiple dex files define Lcom/nineoldandroids/animation/Anima
我尝试运行我的 android 应用程序,但出现此错误。 [2014-03-11 11:21:34 - Dex Loader] Unable to execute dex: Multiple dex
我希望指定包中的所有类都驻留在主 dex 文件中。 那里有使用通配符的选项吗? 最佳答案 很遗憾,不支持通配符。 但是,您可以使用 this script 生成 main-dex-list 文件。 .
我目前有一个来自霍尼韦尔的 DEX BLE-1 适配器,用于从自动售货机检索 dex 数据。我有一个 swift 3 iOS 应用程序,它使用 CoreBluetooth 进行扫描并与外围设备配对。该
我正在使用 IntelliJ IDEA 12.1.4,在我的项目中我使用了几个库/项目: ActionBarSherlock ViewPagerIndicator Volley ProgressShe
我在尝试运行我的项目时遇到了这个问题 - com.android.builder.dexing.DexArchiveBuilderException: Failed to process .gradl
我一直在四处寻找,有很多帖子与这个问题有关,但似乎没有确定的解决方案(例如 Error when building apk - "Multiple dex files define Lcom/goog
我正在对 Jan Berkel 的 SBT Android 插件进行一些黑客攻击,我在想是否有一种方法可以将多个 .dex 文件合并到一个 .dex 文件中包含所有这些。 例如,如果我有这个: cla
我在尝试运行我的应用程序时遇到了这些问题,但不知道如何解决... 谁能帮帮我 这是错误: [2014-04-18 18:47:35 - Dex Loader] Unable to execute de
这个问题在这里已经有了答案: Android support multidex library implementation (4 个回答) 4年前关闭。 生成签名的apk时,有这个错误,但构建项目是
我有一个 Android 应用程序,(理论上)它可以变成一个库并放入外部应用程序中。然后外部应用程序可以创建一个包含我的应用程序的选项卡。库应用程序的设置方式与 google-play-service
我正在开发一个 android 应用程序并且 gradle 构建工作正常但是现在当我构建我的 android 项目时,gradle 构建失败并显示以下错误 Error converting bytec
我是一名优秀的程序员,十分优秀!