-
Notifications
You must be signed in to change notification settings - Fork 113
Predex
PLASE REVIEW THIS ARTICLE
IMHO the best way will be to make this text like draft or standard
after that we may edit android-plugin source code and make it cover this text in proper way
What is it? For example, our application depends on Scala. And, for example, we don't want to waste our time on every build iteration. Dex stage on every build that prepare huge apk with big part of stable, immutable code is very ineffective. The simplest decision is to pre generate dex files for all stable dependencies and upload them to our real device or emulator. http://lampwww.epfl.ch/~michelou/android/emulator-android-sdk.html explains how to prepare and upload libraries to Android. But our real application may depends on different libraries, not only Scala. It would be nice to preload all of them and thus reduce build time of our project. Predex is solution.
For example
- http://lampwww.epfl.ch/~michelou/android/emulator-android-sdk.html
- http://zegoggl.es/2011/07/how-to-preinstall-scala-on-your-android-phone.html
- http://scalandroid.blogspot.com/2011/07/adding-scala-libraries-to-android.html
and so on...
This method is complex and have some drawbacks. You must modify runtime environment (emulator img file) every time when library list modified. Also all libraries loaded at the boot time so some broken stuff may blow up boot sequence of our device. This way mostly suitable for real people that acquire pleasure from solving different puzzles, especially with boot sequence.
There is not any example because this method very simple. Google provide it for loading shared libraries and using it widely. You may read more about Android share libraries in “beautiful and detailed” Android documentation, or source code... Just modify emulator image once and make /system/etc/permissions writable or use real device. After that upload XML library descriptors to /system/etc/permissions, pregenerated dex libraries to /data and reboot device. That's all. Next time we apply our changes without any environment modification - only overwrite exist library or upload new. At the end of modification process (adb push) we reboot our device. The whole process can be completed in a few seconds. Reboot will take longer ;-) Permission descriptors generated for every predexed library by plugin automatically. We must add reference for every shared library to development version of our AndroidManifest.xml like this:
dxOpt the only predex setting, keep it simple.
dxOpts in Android := ("-JXmx512m", None)
dxOpts in Android := ("-JXmx512m", Some(Seq()))
dxOpts in Android := ("-JXmx512m", Some(Seq(".*")))
dxOpts in Android := ("-JXmx512m", Some(Seq(".*/digilib.*")))
Predex stage is disabled. APK file generated without Proguard
Predex stage is enables. APK file generated without Proguard. APK file based on “classes.dex” that contain only application classes from sbt 'android:class-directory'. All dependencies processes as external dex libraries and located at sbt 'android:classes-dex-path'/predex directory.
Predex stage is enables. APK file generated without Proguard. APK file based on “classes.dex” that contain application classes from sbt 'android:class-directory' directory AND dependencies that match out regular expression. All OTHER dependencies processes as external dex libraries and located at sbt 'android:classes-dex-path'/predex directory.
Predex stage is disabled while proguard is turned on. APK file generated with Proguard.
1st time build with sbt
- Upload pregenerated dex files located at sbt 'android:classes-dex-path'/predex directory to /data, if needed
- Upload created xml security handler template to /system/etc/permissions, if needed
- Reboot device if needed (predex libraries modified)
- Next we run APK to our real device or emulator
Make sure, that that XML file point to proper library location (/data by default). By default all libraries located in /data directory. There are several reasons for such location: /data always accessible, /data located on EFS partition with POSIX file system object permission model, /data available early at boot process, and the last one is in normal environment /data directory contains no files, only directories. Now, Android environment ready for our stripped APK package.
2nd time build with sbt
Predex libraries are already cached.
- All steps skipped except stripped APK generation.
Our build time reduced. Problem solved
- Getting started
- Scala versions
- Android Manifest generation
- Typed resources references
- ProGuard
- DDMS integration
- Building Java Android projects
- Building NDK projects
- Consuming Android Library projects
- Github integration
- Building Android Test Projects
- Password Manager
- Releasing to the Android Market
- Projects using sbt-android-plugin
- Contributors