問(wèn)題描述
我最近發(fā)現(xiàn)了來(lái)自 Android 的新 MultiDex 功能,可用于處理具有 65,000 多個(gè)引用的應(yīng)用程序.參見(jiàn):https://developer.android.com/tools/building/multidex.html一個(gè)>
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
誰(shuí)能幫我理解以下問(wèn)題:
Can someone help me understand the following questions:
1) Gradle 構(gòu)建插件如何確定在主 dex 文件 (classes.dex) 和輔助 dex 文件中放置什么?根據(jù)文檔,主 dex 中需要某些東西,但它沒(méi)有給出任何示例.是否所有活動(dòng)都必須在主 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?
引用文字:
對(duì)于需要哪些類(lèi)有復(fù)雜的要求在 Dalvik 運(yùn)行時(shí)執(zhí)行時(shí)的主 dex 文件.安卓構(gòu)建工具更新處理 Android 要求,但它是其他包含的庫(kù)可能有額外的依賴關(guān)系要求,包括使用自省或調(diào)用 Java來(lái)自本機(jī)代碼的方法.部分庫(kù)可能無(wú)法使用直到 multidex 構(gòu)建工具更新以允許您指定必須包含在主 dex 文件中的類(lèi).
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) 及更高版本構(gòu)建時(shí),Gradle Build Plugin 中的行為有所不同.它說(shuō)它要快得多,因?yàn)樗鼘?yīng)用程序的每個(gè)模塊(包括依賴項(xiàng))構(gòu)建為單獨(dú)的 dex 文件.這通常稱(chēng)為預(yù) dexing."Android中模塊的定義是什么?這是這里提到的 Java 庫(kù)、Android 庫(kù)和 Android 應(yīng)用程序模塊嗎:http://developer.android.com/sdk/installing/studio-build.html#projectModules?遠(yuǎn)程或本地二進(jìn)制依賴項(xiàng)(例如:Jars)是否算作單獨(dú)的模塊,因此會(huì)被放入不同的 dex 文件中,還是根據(jù)它們被包含在模塊中?
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 插件內(nèi)部使用 Proguard 在 intermediates/multi-dex
構(gòu)建文件夾中創(chuàng)建兩個(gè) jar 文件.一個(gè)將是主 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
任務(wù)負(fù)責(zé)為proguard 創(chuàng)建keep 文件,你可以在我上面提到的文件夾的variant 特定子目錄中看到這個(gè)文件和其他proguard 參數(shù).希望從長(zhǎng)遠(yuǎn)來(lái)看,這將是可定制的.
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.
目前還有一個(gè)與 gradle 插件的 1.0.0-rc1 中的測(cè)試項(xiàng)目相關(guān)的錯(cuò)誤 (https://code.google.com/p/android/issues/detail?id=80741).通過(guò)一些小的更改,我在那里發(fā)布的解決方法也可用于立即將您自己的條目添加到保留列表中(從而確保您的類(lèi)最終在主 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 的角度來(lái)看,模塊是指模塊,但這些確實(shí)可以是您鏈接到的列表中提到的不同項(xiàng)目.如果您從命令行使用 --info
作為標(biāo)志進(jìn)行 pre-lollipop gradle 構(gòu)建,您可以看到所有 dex 文件都被傳遞到 dx
.(請(qǐng)注意,這不應(yīng)該是啟用了 multidex 的構(gòu)建或具有 preDexLibraries = false
的構(gòu)建).
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
).
這篇關(guān)于Android MultiDex - 關(guān)于內(nèi)部工作的問(wèn)題的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!