jberkel / android-plugin

An sbt plugin for Android development in Scala
https://groups.google.com/forum/#!forum/scala-on-android
Other
476 stars 113 forks source link

Skipping ProGuard when using shared Scala libraries #20

Open liff opened 14 years ago

liff commented 14 years ago

It seems to be possible to set up the emulator with a shared copy of the Scala libraries:

http://lamp.epfl.ch/~michelou/android/emulator-android-sdk.html

When the emulator has been set up in this way, the ProGuard step could be skipped (it's rather slow).

jberkel commented 13 years ago

interesting. with the current master you can do:

override def skipProguard = true

to skip the proguard step.

appamatto commented 13 years ago

I've noticed proguard still getting executed with this override. I'm quite baffled--looking at the code this should never happen, unless I'm misunderstanding the semantics of "lazy".

jberkel commented 13 years ago

you actually need to put the override into both projects (main + test):

 trait Defaults extends BaseAndroidProject {
    def androidPlatformName = "android-7"
    override def skipProguard = true
 }

class MainProject(info: ProjectInfo) extends AndroidProject(info) with Defaults { ... }
class TestProject(info: ProjectInfo) extends AndroidTestProject(info) with Defaults
jberkel commented 13 years ago

just tried it with a patched emulator image as described above - it works fine, and speeds up the development process considerably. i've mirrored the svn repo with the scripts to generate the patched emulator images: https://github.com/jberkel/android-sdk-scala

here's what i did:

$ git clone git://github.com/jberkel/android-sdk-scala.git && cd android-sdk-scala
$ bin/createdexlibs  # predex scala lib
$ bin/createramdisks # patch imgs to include scala in BOOTCLASSPATH
$ emulator -avd ... -ramdisk /path/to/custom.img
$ adb shell mkdir -p /data/framework
$ for i in configs/framework/*.jar; do adb push $i /data/framework/$(basename $i); done
$ adb shell echo '$BOOTCLASSPATH'
/system/framework/core.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/data/framework/scala-library.jar:/data/framework/scala-collection.jar:/data/framework/scala-immutable.jar:/data/framework/scala-mutable.jar:/data/framework/scala-actors.jar  

then after rebooting the emulator you can install scala apks on the emulator.

i'd like to make the steps needed to get the emulator to accept scala apks simpler - maybe we could add an sbt task for it ?

quick benchmark (hello world project generated by g8, main apk + tests) with proguard:

$ time sbt clean package-debug
real    0m40.514s
user    0m50.632s
sys 0m2.345s

without proguard:

$ time sbt clean package-debug
real    0m16.507s
user    0m22.199s
sys 0m1.873s

woot!

jrudolph commented 13 years ago

I pre-packaged the Scala libs for Android so that, after installing, you can reference them in your AndroidManifest.xml with tags for developing purposes. You can find it at jrudolph/scala-android-libs .

charroch commented 13 years ago

nice one jrudolph

Macarse commented 13 years ago

I got here after asking this question: http://stackoverflow.com/questions/7941178/long-build-times-with-sbt-android-plugin

I will use scala in my application for a small part. I was thinking of trying to package that code in some kind of library to avoid the compile time.

Anyone tried something like that?