Tuesday, March 27, 2012

Solving Initial Compilation Issues with Android

Two weeks ago I helped with a beginner's Android Workshop at Mobile March.  A lot of the people had problems getting their development environment up and running - but for reasons that weren't really any fault of their own, or were easily overlooked.  Typically once you've got all the gears in place building is simple, but I'd forgotten how surprisingly difficult it can be to get a project up and running in Eclipse initially.

Here's a few common problems I saw around the classroom:

- Installing the Android SDK (the tools for Android) but not the ADT plugin (how Eclipse interfaces with the SDK), or vice versa.  Make sure both are installed.

- Not installing any Android platforms (or not installing the correct one for the app you're trying to build).  The SDK is just a starter package - from there, you need to run the Android SDK Manager and add SDK components.  There's an SDK platform for each version of Android; I recommend just installing the whole lot (it takes time to download, but makes everything else easy).

- If you get compilation errors upon importing a project, do a full clean and rebuild.  Clean is found in Project --> Clean.  This can sometimes clear up import issues.

- Compilation issues with @Override.  If you're getting compilation error on @Override, that's because your JDK compliance level is set incorrectly.  You either need to go into Eclipse --> Preferences --> Java --> Compiler and set the compliance level to 1.6+, or you need to go into the individual project and change that setting (right-click the project --> Properties --> Java Compiler --> Compiler compliance level).


- Using emulators that are not compatible with your sample app.  If your app targets 2.3, you must have a 2.3 (or higher) emulator.  If your app uses Google Maps, your emulator must be a "Google APIs" emulator (and also conform to the previous version requirement as well).


- Did you try Android briefly more than a year ago and now it refuses to work?  Chances are the problem is an invalid debug.keystore.  When you build in Eclipse, it creates your APK using an automatically generated debug keystore.  Older versions of Android had these set to expire a year after creation, so if you dabbled in Android before it may have expired.  You can find the path to your debug.keystore by going into Preferences --> Android --> Build.  You can safely delete your old debug.keystore and the Android build process will automatically create a new, valid one for you.

- If none of the above helps, I found the most useful debugging tool for build errors was to turn on verbose output.  You can turn that on in Preferences --> Android --> Build --> Build Output, then check the Console for any salient error messages.

Good luck getting your first Android app building!

Thursday, March 1, 2012

Upcoming Talks: AnDevCon III and Mobile March 3D

I'm going to be speaking at AnDevCon III!  My talk is called "Don't Make Me Repeat Myself: Tips and Tricks to Avoid Code Duplication and Increase Code Reuse on Android".  You can find a long description of it here.

If you register, you can use my last name ("LEW") as a $200 off coupon.  This coupon should be valid all the way up till the conference.  Also, if you register before March 2nd you get some pretty deep discounts.

I'm slated to give a demo version of this talk at the April AUG.MN meetup (April 3rd), if you happen to be near the Twin Cities.

I thought I'd also mention that I'm going to be briefly demoing Mobiata's apps at Mobile March's 3D event.   I'll also be helping out with the Android workshop on Friday.  Say hello if you happen to see me around.