問題描述
我最近發現了來自 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 - 關于內部工作的問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!