开发者

Android, Scala and Proguard

After running headfirst into as many problems as there are permutations of the set of Andr开发者_JAVA百科oid command-line tools, I finally managed to compile a mix of Scala and Java source code into a usable apk.

As many suggest, I used proguard to squeeze the Scala library through the dex tool. The problem is this:

BUILD SUCCESSFUL
Total time: 1 minute 29 seconds

One minute and a half. We're talking about an application with Hello-World complexity here. I don't think I can develop like that. I'm gonna need to take meditation classes.

This is the proguard configuration:

-injars ${out.absolute.dir}/classes:${scala-library.jar}(!META-INF/MANIFEST.MF,!library.properties)
-outjars ${out.absolute.dir}/classes.min.jar
-libraryjars ${android.jar}
-dontwarn
-dontoptimize
-dontobfuscate
-keep public class * extends android.app.Activity

Is there a way to speed up the proguard step?

Edit: I'm running this in a pretty decent dual-core, 3GB ram machine, on top of 64-bit Linux. A run of ant compile (scalac/javac) takes 3 seconds. A full ant install takes 1:30, as described above. It's the proguard step that "freezes", according to the output, most likely because of the scala/android runtime lib sizes.


Working via android Ant builds is probably not the right way to go about this.

The current "best advice" is to use SBT with the

  • proguard (https://github.com/siasia/xsbt-proguard-plugin) and
  • android (https://github.com/jberkel/android-plugin)

plugins.


ProGuard takes a lot longer to shrink the Scala 2.9.1 library than the Scala 2.8.1 library (54 seconds vs. 13 seconds, for 8.5 MB vs. 6.2 MB). Either the structure of the library classes has changed fundamentally, or some new classes are causing excessive computations. I'll have to figure out if ProGuard or its configuration can be improved for this case. For now, you might be able to work with Scala 2.8.1.

I'm assuming your ProGuard configuration also contains the required options for Android and for Scala, as discussed in the ProGuard manual. If you are using the regular Android build process, the input (classes, libs) and libraries (android.jar) are already specified for you in the Ant build file, and you don't need to specify them again in the ProGuard configuration file. Reading them twice will just take time and generate many warnings (which you have switched off completely -- it's safer to switch them off selectively).


If you have a rooted phone and only want to test on this you can install the scala libs directly on your phone so you don't need the proguard step anymore:

https://github.com/jrudolph/scala-android-libs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜