Android MultiDex - 关于内部工作的问题

Android MultiDex - Questions on Inner Workings(Android MultiDex - 关于内部工作的问题)
本文介绍了Android MultiDex - 关于内部工作的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我最近发现了来自 Android 的新 MultiDex 功能,可用于处理具有 65,000 多个引用的应用程序.参见:https://developer.android.com/tools/building/multidex.html

I recently discovered the new MultiDex functionality from Android for working with apps having more than 65,000 references. See: https://developer.android.com/tools/building/multidex.html

谁能帮我理解以下问题:

Can someone help me understand the following questions:

1) Gradle 构建插件如何确定在主 dex 文件 (classes.dex) 和辅助 dex 文件中放置什么?根据文档,主 dex 中需要某些东西,但它没有给出任何示例.是否所有活动都必须在主 dex 文件中?

1) How does the Gradle build plugin determine what to put in the primary dex file (classes.dex) vs the secondary dex files? Based on the doc there are certain things required to be in primary dex but it doesn't give any examples. Are all activities required to be in the primary dex file?

引用文字:

对于需要哪些类有复杂的要求在 Dalvik 运行时执行时的主 dex 文件.安卓构建工具更新处理 Android 要求,但它是其他包含的库可能有额外的依赖关系要求,包括使用自省或调用 Java来自本机代码的方法.部分库可能无法使用直到 multidex 构建工具更新以允许您指定必须包含在主 dex 文件中的类.

There are complex requirements regarding what classes are needed in the primary dex file when executing in the Dalvik runtime. The Android build tooling updates handle the Android requirements, but it is possible that other included libraries have additional dependency requirements including the use of introspection or invocation of Java methods from native code. Some libraries may not be able to be used until the multidex build tools are updated to allow you to specify classes that must be included in the primary dex file.

2) 仅为 Android API Level 21 (Android L) 及更高版本构建时,Gradle Build Plugin 中的行为有所不同.它说它要快得多,因为它将应用程序的每个模块(包括依赖项)构建为单独的 dex 文件.这通常称为预 dexing."Android中模块的定义是什么?这是这里提到的 Java 库、Android 库和 Android 应用程序模块吗:http://developer.android.com/sdk/installing/studio-build.html#projectModules?远程或本地二进制依赖项(例如:Jars)是否算作单独的模块,因此会被放入不同的 dex 文件中,还是根据它们被包含在模块中?

2) When building only for Android API Level 21 (Android L) and above, there is different behavior in the Gradle Build Plugin. It says it is much faster because it "Builds each module of the application (including dependencies) as separate dex files. This is commonly referred to as pre-dexing." What is the definition of a module in Android? Is this the Java Library, Android Library, and Android application modules mentioned here: http://developer.android.com/sdk/installing/studio-build.html#projectModules? Do Remote or Local Binary Dependencies (ex:Jars) count as separate modules and thus get put into a different dex file or do they get included in the module depending on them?

推荐答案

1) gradle 插件内部使用 Proguard 在 intermediates/multi-dex 构建文件夹中创建两个 jar 文件.一个将是主 dex,其余的将分布在 dex 2、3 等上.

1) The gradle plugin internally uses Proguard to create two jar files in the intermediates/multi-dex build folder. One will be the primary dex, the rest will be spread out over dex 2, 3 etc.

collect{variant}MultiDexComponents 任务负责为proguard 创建keep 文件,你可以在我上面提到的文件夹的variant 特定子目录中看到这个文件和其他proguard 参数.希望从长远来看,这将是可定制的.

The collect{variant}MultiDexComponents task is responsible for creating the keep file for proguard, you can see this file and other proguard parameters used in the variant specific subdirectory of the folder I mentioned above. Hopefully this will be customisable in the long run.

目前还有一个与 gradle 插件的 1.0.0-rc1 中的测试项目相关的错误 (https://code.google.com/p/android/issues/detail?id=80741).通过一些小的更改,我在那里发布的解决方法也可用于立即将您自己的条目添加到保留列表中(从而确保您的类最终在主 dex 中).

There is also currently a bug relating to test projects in 1.0.0-rc1 of the gradle plugin (https://code.google.com/p/android/issues/detail?id=80741). With some small changes the workaround I posted there can also be used to add your own entries to the keep list (thus ensuring your classes end up in the primary dex) right now.

2) 从 Gradle 的角度来看,模块是指模块,但这些确实可以是您链接到的列表中提到的不同项目.如果您从命令行使用 --info 作为标志进行 pre-lollipop gradle 构建,您可以看到所有 dex 文件都被传递到 dx.(请注意,这不应该是启用了 multidex 的构建或具有 preDexLibraries = false 的构建).

2) Modules refer to modules from a Gradle perspective, but these can indeed be the different items mentioned in the list you linked to. If you do a pre-lollipop gradle build from the commandline with --info as a flag you can see all the dex files being passed to dx. (Note that this should not a multidex enabled build or one with preDexLibraries = false).

这篇关于Android MultiDex - 关于内部工作的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)