It's easy to enable multi-dex option for gradle build system, but I haven't found example how I can enable this option for ant building. How can archive this?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I also added multidex to the ANT build, but in a slightly different fashion that is more flexible in the classes*.dex support.
In any case, I did this in two phases: 1) get DX to output multidex then 2) use aapt to include the multidex classes. There is an optional step for producing the main classes list at the end of this posting but it is not necessary for the basic implementation.
Here's the implementation in build.xml, with comments to follow:
Modification (1) replaces the -package target to allow extra jars to be passed to ApkBuilder. It turns out ApkBuilder just copies the contents of the JAR files into the APK, so if we put our classes[1-N].dex into a JAR we can get ApkBuilder to package those extra jars into the APK.
(2) Builds that extra JAR file with all classes*.dex except classes.dex, so supports any number of extra classes.dex files
(3) Is a work around for that fact that the "dex" AntTask does not support any way to pass --multi-dex to "dx.bat", which knows how to use it. I looked at what dx.bat was invoking and added that directly here (Amended: michaelbrz has a better implementation in his script so I borrowed it. Thank you)
BTW, we always run Proguard (either obfuscated or unobfuscated) to get class and method shrinkage. This is handy for generating a "main class" list. In our case, we added Google Play Services and that blew our DEX file method limit, so decided to put those classes and methods in the secondary dex. Generating that class list from the Proguard output is a simple matter of filtering dump.txt:
We have 2 options:
Hope, that it helps.
I introduced multi-dex support in application using ant based on Ruboto's build.xml (kudos to them!). So that's the path I would recommend to take. In that case you don't have to create custom ant jars, just edit your build.xml and apply all non-gradle steps from https://developer.android.com/tools/building/multidex.html
As for build.xml you would have to take a look if all paths play well with each other, you might have changed some of them and need to adjust ant steps.
In my case I had to also generate list of classes that must be placed in first generated dex (default one), so the app could even start as it loads additional dexes in Application's onCreate. In order to do that you need to run script mainDexClasses, which you will find in your build-tools:
Alex Lipov wrote nice post about it.
When you have list of classes generated, you have to point to this list in dx's parameter by adding
where dx is executed.
It's worth remembering that Ruboto's script assumes that only one additional dex will be created, which is not always case. I had two additional dexes generated so I implemented adding if exists:
And multidex support in Ant is on! It's not as easy as with gradle, but it's possible.
UPDATE: my build.xml (apart from not answer-related parts):