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

add ability to predex external libraries #107

Closed ezh closed 12 years ago

ezh commented 12 years ago

Add ability to predex project dependencies with dxOpt (modified dxJavaOpt) This is allow preload external jars (like scala runtime) to android device. We're able to significantly reduce time to build apk at development stage.

Predex jar generated at classesDexPath / predex, also simple permission descriptor generated for /system/etc/permissions. Proguard must be switched off, of course.

After that we preload libraries at emulator or device and add something like that :-)

<uses-library android:name="slf4j-android-1.6.1-RC1" android:required="true"/>

to AndroidManifest.xml

Work flawlessly with Eclipse 3.7.1, ScalaIDE 2, scala 2.9.1, sbt 0.11.2

ezh commented 12 years ago

Add ability to filter predex libraries. This is allow to put some libraries(unstable) in classes.dex and other libraries hold as dex jars

For example, add dxOpts in Android := ("-JXmx512m", Some(Seq("./digilib."))) to push all . * /digilib. * in classes dex

Output for example (1st run): ... [info] Skipping Proguard [debug] apply filter "./digilib." to "/home/ezh/0projectsAndroid/digiSSHD/lib/CWAC-MergeAdapter.jar" [debug] apply filter "./digilib." to "/home/ezh/0projectsAndroid/digiSSHD/lib/CWAC-SackOfViewsAdapter.jar" [debug] apply filter "./digilib." to "/home/ezh/0projectsAndroid/digiSSHD/lib/digilib2.8.2-0.0.1.jar" [debug] apply filter "./digilib._" to "/home/ezh/.ivy2/cache/org.slf4j/slf4j-android/jars/slf4j-android-1.6.1-RC1.jar" [debug] pack in dex "classes" [debug] pack in dex "digilib_2.8.2-0.0.1.jar" [debug] pack in predex "CWAC-MergeAdapter.jar" [debug] pack in predex "CWAC-SackOfViewsAdapter.jar" [debug] pack in predex "slf4j-android-1.6.1-RC1.jar" [debug] /home/ezh/0projectsAndroid/android-sdk-linux/platform-tools/dx -JXmx512m --dex --output=/home/ezh/0projectsAndroid/digiSSHD/bin/classes.dex /home/ezh/0projectsAndroid/digiSSHD/bin/classes /home/ezh/0projectsAndroid/digiSSHD/lib/digilib_2.8.2-0.0.1.jar [info] Dexing /home/ezh/0projectsAndroid/digiSSHD/bin/classes.dex [debug] [debug] /home/ezh/0projectsAndroid/android-sdk-linux/platform-tools/dx -JXmx512m --dex --output=/home/ezh/0projectsAndroid/digiSSHD/bin/predex/CWAC-MergeAdapter.jar /home/ezh/0projectsAndroid/digiSSHD/lib/CWAC-MergeAdapter.jar ...

2nd run: [info] Skipping Proguard [debug] apply filter "./digilib." to "/home/ezh/0projectsAndroid/digiSSHD/lib/CWAC-MergeAdapter.jar" [debug] apply filter "./digilib." to "/home/ezh/0projectsAndroid/digiSSHD/lib/CWAC-SackOfViewsAdapter.jar" [debug] apply filter "./digilib." to "/home/ezh/0projectsAndroid/digiSSHD/lib/digilib2.8.2-0.0.1.jar" [debug] apply filter "./digilib._" to "/home/ezh/.ivy2/cache/org.slf4j/slf4j-android/jars/slf4j-android-1.6.1-RC1.jar" [debug] pack in dex "classes" [debug] pack in dex "digilib2.8.2-0.0.1.jar" [debug] pack in predex "CWAC-MergeAdapter.jar" [debug] pack in predex "CWAC-SackOfViewsAdapter.jar" [debug] pack in predex "slf4j-android-1.6.1-RC1.jar" [debug] dex file /home/ezh/0projectsAndroid/digiSSHD/bin/classes.dex uptodate, skipping [debug] dex file /home/ezh/0projectsAndroid/digiSSHD/bin/predex/CWAC-MergeAdapter.jar uptodate, skipping [debug] dex file /home/ezh/0projectsAndroid/digiSSHD/bin/predex/CWAC-SackOfViewsAdapter.jar uptodate, skipping [debug] dex file /home/ezh/0projectsAndroid/digiSSHD/bin/predex/slf4j-android-1.6.1-RC1.jar uptodate, skipping [debug] packaging: /home/ezh/0projectsAndroid/android-sdk-linux/platform-tools/aapt package --auto-add-overlay -f -M /home/ezh/0projectsAndroid/digiSSHD/AndroidManifest.xml -S /home/ezh/0projectsAndroid/digiSSHD/res -A /home/ezh/0projectsAndroid/digiSSHD/assets -I /home/ezh/0projectsAndroid/android-sdk-linux/platforms/android-8/android.jar -F /home/ezh/0projectsAndroid/digiSSHD/bin/resources.ap

dexdump classes.dex |grep 'Class descriptor' | grep lib Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$$anonfun$act$1$$anonfun$apply$1;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$$anonfun$act$1;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$Abstract;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$Disconnect$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$ListInterfaces$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$PrepareEnvironment$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$Setup$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$Start$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$Status$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Message$Stop$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$State$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Status$$anonfun$1;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Status$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application$Status;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Application;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/ApplicationActivity$$anon$1;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/ApplicationActivity$$anonfun$onResume$1;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/ApplicationActivity$class;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/ApplicationActivity;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Service$State$;' Class descriptor : 'Lorg/digimead/digi/inetd/lib/Service;'

ls predex CWAC-MergeAdapter.jar CWAC-MergeAdapter.xml CWAC-SackOfViewsAdapter.jar CWAC-SackOfViewsAdapter.xml slf4j-android-1.6.1-RC1.jar slf4j-android-1.6.1-RC1.xml

So jar digilib_2.8.2-0.0.1.jar merged with classes.dex and all other libraries saved as pregenerated. Now we may upload it to emulator and use AndroidManifest.xml with

    <uses-library
        android:name="scala.actors"
        android:required="true" />
    <uses-library
        android:name="scala.library"
        android:required="true" />
    <uses-library
        android:name="scala.collection"
        android:required="true" />
    <uses-library
        android:name="scala.collection.mutable"
        android:required="true" />
    <uses-library
        android:name="scala.collection.immutable"
        android:required="true" />
    <uses-library
        android:name="slf4j-android-1.6.1-RC1"
        android:required="true" />
    <uses-library
        android:name="CWAC-MergeAdapter"
        android:required="true" />
    <uses-library
        android:name="CWAC-SackOfViewsAdapter"
        android:required="true" />
    <uses-library
charroch commented 12 years ago

+1 for this

saynomoo commented 12 years ago

This is fantastic stuff! The patches does not however seem to merge to jberkel/master. I suppose the pull request should be updated

ezh commented 12 years ago

Synchronized with master branch of 0.6.2-SNAPSHOT at Wed, 23 May 2012 17:53:28 +0400 This ability actively used in development process of DigiSSHD/DigiControl

Example of DigiControl compilation. Resource generation is the most greedy operation now :-(

jberkel commented 12 years ago

merged, thanks. would you mind adding some docs to the wiki?

ezh commented 12 years ago

Absolutely. Also I did mistake in code comments "prodaction" vs "production". So sorry. Please feel free to correct me, when necessary. I am not native speaker, so there are some glitches ;-)