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

0.7 Snapshot #181

Closed fxthomas closed 11 years ago

fxthomas commented 11 years ago

I've been using this branch for a few weeks now to create a small app that I will publish on the Play Store soon, and I believe it is stable enough to be pushed to master. If you find anything bad, let me know!

See the tutorial for a more complete overview on how to use the plugin, and see the posts on the mailing list for some bugs and issues that have been ironed out.

jberkel commented 11 years ago

quite a big PR, but looks good. would also be good to have an updated g8 template to use with with 0.7-SNAPSHOT, didn't find any on your github repo.

fxthomas commented 11 years ago

Ah, yes, the g8 template is not up-to-date, thanks for reminding me! I'll push a commit as soon as I can to change that. In the meantime, fxthomas/android-scratch is a dead-simple example for a small project.

The request is pretty large indeed -- I was hoping to submit more often, but my first commits were a little experimental and weren't very interesting by themselves, so I ended up rebasing them when I pulled from the 0.6.4 release.

Anyway, the large bulk of my improvements is in the first commit. The next commits are mainly bug fixes thanks to the feedback I got on the list.

MHOOO commented 11 years ago

I tried your android-scratch project, but I get the following exception when trying it in the emulator:

D/AndroidRuntime( 1767): 
D/AndroidRuntime( 1767): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
D/AndroidRuntime( 1767): CheckJNI is ON
D/dalvikvm( 1767): Trying to load lib libjavacore.so 0x0
D/dalvikvm( 1767): Added shared lib libjavacore.so 0x0
D/dalvikvm( 1767): Trying to load lib libnativehelper.so 0x0
D/dalvikvm( 1767): Added shared lib libnativehelper.so 0x0
D/AndroidRuntime( 1767): Calling main entry com.android.commands.am.Am
I/ActivityManager( 1007): START {act=android.intent.action.MAIN flg=0x10000000 cmp=com.scratch/.ScratchActivity u=0} from pid 1767
D/dalvikvm( 1007): GC_FOR_ALLOC freed 79K, 9% free 15079K/16519K, paused 9ms, total 9ms
I/dalvikvm-heap( 1007): Grow heap (frag case) to 15.168MB for 380492-byte allocation
D/dalvikvm( 1007): GC_FOR_ALLOC freed <1K, 9% free 15450K/16903K, paused 5ms, total 5ms
D/dalvikvm( 1779): Not late-enabling CheckJNI (already on)
I/ActivityManager( 1007): Start proc com.scratch for activity com.scratch/.ScratchActivity: pid=1779 uid=10043 gids={1028}
E/Trace   ( 1779): error opening trace file: No such file or directory (2)
W/dalvikvm( 1779): VFY: unable to resolve static field 1 (main) in Lcom/scratch/R$layout;
D/dalvikvm( 1779): VFY: replacing opcode 0x60 at 0x0003
D/AndroidRuntime( 1779): Shutting down VM
W/dalvikvm( 1779): threadid=1: thread exiting with uncaught exception (group=0xaee78288)
E/AndroidRuntime( 1779): FATAL EXCEPTION: main
E/AndroidRuntime( 1779): java.lang.NoClassDefFoundError: com.scratch.R$layout
E/AndroidRuntime( 1779):        at com.scratch.ScratchActivity.onCreate(ScratchActivity.scala:9)
E/AndroidRuntime( 1779):        at android.app.Activity.performCreate(Activity.java:5008)
E/AndroidRuntime( 1779):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
E/AndroidRuntime( 1779):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
E/AndroidRuntime( 1779):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
E/AndroidRuntime( 1779):        at android.app.ActivityThread.access$600(ActivityThread.java:130)
E/AndroidRuntime( 1779):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
E/AndroidRuntime( 1779):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 1779):        at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1779):        at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 1779):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1779):        at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1779):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 1779):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 1779):        at dalvik.system.NativeStart.main(Native Method)
D/AndroidRuntime( 1767): Shutting down VM
D/dalvikvm( 1767): GC_CONCURRENT freed 97K, 77% free 473K/2048K, paused 0ms+0ms, total 0ms
W/ActivityManager( 1007):   Force finishing activity com.scratch/.ScratchActivity
D/dalvikvm( 1007): GC_FOR_ALLOC freed 404K, 11% free 15095K/16903K, paused 9ms, total 10ms
W/ActivityManager( 1007): Activity pause timeout for ActivityRecord{afcc2e70 com.scratch/.ScratchActivity}
D/dalvikvm( 1169): GC_FOR_ALLOC freed 5311K, 32% free 15138K/22151K, paused 26ms, total 39ms
D/dalvikvm( 1169): GC_FOR_ALLOC freed 364K, 31% free 15422K/22151K, paused 19ms, total 19ms
I/dalvikvm-heap( 1169): Grow heap (frag case) to 16.706MB for 1644556-byte allocation
D/dalvikvm( 1169): GC_FOR_ALLOC freed 65K, 24% free 16962K/22151K, paused 4ms, total 4ms
D/dalvikvm( 1169): GC_CONCURRENT freed 0K, 24% free 16962K/22151K, paused 19ms+0ms, total 21ms
D/dalvikvm( 1169): GC_CONCURRENT freed 2444K, 26% free 16470K/22151K, paused 20ms+1ms, total 28ms
D/dalvikvm( 1169): GC_FOR_ALLOC freed 996K, 23% free 17264K/22151K, paused 20ms, total 21ms
D/dalvikvm( 1169): GC_FOR_ALLOC freed 1776K, 22% free 17398K/22151K, paused 2ms, total 3ms
I/Process ( 1779): Sending signal. PID: 1779 SIG: 9
I/ActivityManager( 1007): Process com.scratch (pid 1779) has died.
W/InputMethodManagerService( 1007): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@afcd3ab0 attribute=null
W/ActivityManager( 1007): Activity destroy timeout for ActivityRecord{afcc2e70 com.scratch/.ScratchActivity}
fxthomas commented 11 years ago

@MHOOO : Which OS? Are you using the project out-of-the-box or did you make changes? Can you run show sources and tell me what's inside it?

I just tried it, and it definitely works for me - I'm on OSX 10.7, Android SDK r22.0.1, not sure if this is relevant.

fxthomas commented 11 years ago

@jberkel : PR sent to the Giter8 template!

MHOOO commented 11 years ago

@fxthomas Out-of-the-box project without any changes made to it. I am running Ubuntu 12.10, android-sdk_r22.0.1-linux and OpenJDK 1.7.0_21. The command "show" does not exist on ubuntu. What does it do? Maybe I can find an alternative.

fxthomas commented 11 years ago

@MHOOO : Sorry about the late answer. show is not an Ubuntu but an SBT command, which you can run in the SBT console.

Can you describe the steps you used to build the app?

MHOOO commented 11 years ago

I did everything as described in the readme, nothing else. Here's how I got it to work though: I added the following line to the build.sbt

proguardOptions += "-keep class com.scratch.**"

Turned out proguard simply removed the R class.

MHOOO commented 11 years ago

@fxthomas Just making sure you get notified of above message (forgot to @ you)

fxthomas commented 11 years ago

Could you maybe post the contents of the ProGuard configuration? They are saved under target/scala_2.10/src_managed IIRC.

R.java should be automatically included when generating the resources, but there could be something I overlooked.

MHOOO commented 11 years ago

@fxthomas I have made additions to the proguard configuration options, so its grown larger than initially. But I think this should still help to track the issue. target/scala_2.10/src_managed/proguard.txt: https://gist.github.com/MHOOO/61aaddaf22bb26e63c65 build.sbt: https://gist.github.com/MHOOO/94ae783284c690414648

fxthomas commented 11 years ago

Does it still crash if you remove all the extra dependencies?

Did you try removing the target/ directory entirely before rebuilding?

MHOOO commented 11 years ago

I checked out the project again, but did not get the error this time. I've had a similar problem (some files missing) while trying to compile akka for android and the solution there was to switch to java 1.6 (from java 1.7). Turns out I still had java 1.6 active, which is why it worked with the clean checkout. So, the problem came about from using java 1.7 instead of java 1.6.

fxthomas commented 11 years ago

So maybe we need to set the target to Java 6 by default in the plugin? I'll add that when I can!

jkremser commented 11 years ago

I had the same problem with Java 7, after switching to Java 6 it was OK.

appamatto commented 11 years ago

I merged this request. Awesome work, @fxthomas! It's too much to review carefully but we'll be able to address issues as they come up. Thanks!

fxthomas commented 11 years ago

Thanks! As far as bugs are concerned, I will fix them whenever I can, of course!

FYI, I am going to keep on using the plugin to run an app we're developing at work from. I'm not directly working on the app itself, and it's pure Java (no Scala :( ), but 10 minutes here and there should be enough to ensure that sbt-android at least handles it correctly.

Anyway, glad to see it go live! ;)