Thursday, April 23, 2009

Developing for Android Platform

Why Android?
I'm a Java developer. Yes, I could enhance my C/C++ skills, get an iPhone and develop for the iDevices. But, I guess, I wasn't motivated enough. Also, I'm a strong supported of open source development. So, first, I noticed OpenMoko platform. But their development slowed down and stopped. Never got to the point when I'd be able to get a phone and develop for it. Finally, I noticed the Google's Android initiative in late 2007. Yes, I'm afraid of humongous corporations like Micstosoft and now Google. Still, I didn't see a more attractive choice. So, I waited for Google to release the Android phone. I could switch to Windows Mobile platform, but this, somehow, didn't attract me. Finally, in Jan 2009, after living with Palm for good 7 years, and I'm a heavy user of the personal organizers (several years ago, I'd create my own notebooks/calendars, so they'd fit my needs; out of paper and cardboard; I did this for good 2-3 years), finally in Jan 2009, I decided it was time to do the move and I purchased a black G1 (for the picture and a story of my other organizers, see this blog).

Does It Fulfill The Promise?
In short, yes. Is it perfect? No. I can suggest several improvements of the top of my head, even just for hardware. And for software, too, of course. Would I recommend it? Definitely. Does it have a potential? Oh, yes, sure. This section could be a topic on its own, but, it will have to wait for another time. Let's move.

So, to Cut To The Chase, How Do I Develop for Android
Simple. The list of tools I use:
  • Eclipse (3.4.2)
  • JDK (1.6)
  • ADT (0.8.0) - great tool. Can even deploy to the device over USB and monitor the app.
  • Positron aka Autoandroid - for integration testing. Unit testing doesn't work that great for fat clients. This is a great tool except for a few hick-ups.
  • jUnit - for the pieces that can be unit testing without reaching to your left year with your right foot.
Do you want more details, technical details? Sure. Here they're:

Where can I find some sample Android applications?
Well, one good sample is the Android platform itself. For example, to see the source code for the native Android calendar application, you can view it here.

Deploying onto the Device:
  • an unsigned .apk file installs with a "Application installation unsuccessful"
  • log a application crash,,, where can I find it? The ADT displays LogCat.

Using Positron aka Autoandroid:
  • If getting an error about Autoandroid "java.net.SocketException: Connection reset" problem, either:
    • rerun the Android Application and run stories again or
    • application crashed on Android
  • If you get error "Internal Error ... ShouldNotReachHere", do
    • go to the jUnit relevant run configuration, //Classpath// and remove the Android Library from Bootstrap.
    • do //Advanced//, //Add Library// and choose JRE System Library
    • add JUnit library the same way

5 comments:

Hermit_Insane said...

Hi stanb,

I have a problem using the same framework.
I tried using the notepad example from :
http://code.google.com/p/autoandroid/source/browse/#svn/trunk/samples/notepad

I am able to install the app but when I run the stories as junit tests from the eclipse, I get the following error :
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (classFileParser.cpp:3075), pid=1605, tid=3076537232
# Error: ShouldNotReachHere()
#
# JRE version: 6.0_14-b08
# Java VM: Java HotSpot(TM) Client VM (14.0-b16 mixed mode linux-x86 )
# An error report file with more information is saved as:
# /home/rishi/Rapid/notepad/hs_err_pid1605.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp

I tried to remove Android library from the Bootstrap as you had written.
Then I added JRE System Library.
But still no success in running the positron stories.

Please suggest if I am missing something.

Hermit_Insane said...

On removing Android Library form the Bootstrap I am getting the following errors :

java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.junit.internal.runners.TestClassMethodsRunner.createTest(TestClassMethodsRunner.java:52)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:58)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at com.googlecode.autoandroid.positron.Start.run(Start.java:89)
at com.googlecode.autoandroid.positron.Start.run(Start.java:47)
at com.googlecode.autoandroid.positron.junit4.TestCase.*clinit*(TestCase.java:14)
... 16 more
Caused by: java.lang.NullPointerException
at com.googlecode.autoandroid.lib.AndroidTools.locateTool(AndroidTools.java:110)
at com.googlecode.autoandroid.lib.AndroidTools.startTool(AndroidTools.java:103)
at com.googlecode.autoandroid.lib.AndroidTools.startTool(AndroidTools.java:91)
at com.googlecode.autoandroid.lib.UnixAndroidTools.adb(UnixAndroidTools.java:14)
at com.googlecode.autoandroid.positron.Start.run(Start.java:81)
... 18 more

ChDWu said...

thanks, it helps on " Internal Error ..." error!

stanb said...

Hermit_Insane, have you figured it out?

Pastor Plants said...

Awesome, that fixed it. Thank you!