Upgrading to Roboguice 2.0 beta 3.

Last Tuesday night I was feeling brave and decided it was time to upgrade a my current pet Android project to Roboguice 2.0b3. 

To get it all working I needed to...

Upgrade Dependancies

As the project uses Maven I firstly upgraded the Roboguice dependancy in my pom. This also entails upgrading the Google Guice dependancy as well. They now look like this:

 
<dependency>     
    <groupId>org.roboguice</groupId>     
    <artifactId>roboguice</artifactId>     
    <version>2.0b3</version>     
</dependency> <dependency>         

<groupId>com.google.inject</groupId>     
    <artifactId>guice</artifactId>    
     <version>3.0</version>    
     <classifier>no_aop</classifier>
 </dependency> 

This created quite a few errors.

Remove custom application, update modules.

Next step was to remove the custom application class, test and references from the project. The new version of Roboguice doesn't need an application extending RoboApplication.

Once this was gone l needed to let Roboguice know where my custom module is. The simplest way to do this is create a new resource file in res/values called roboguice.xml. Here's my new one https://github.com/davespanton/Nutbar/blob/master/res/values/roboguice.xml

Any custom modules need to be changed to inherit from AbstractModule instead of AbsractAndroidModule. I had to change this for my main custom module and my test module. 

I also had to refactor the main module to no longer take any constructor parameters. It previously took a reference to my application, but this was easily refactored.

Injected Test Runner.

I use Robolectric for unit testing and have an InjectedTestRunner which extends their RobolectricTestRunner. The prepareTest method was updated to:

Preferences Activity.

The only problems I had once the above was done was with my preferences activity injecting a shared preference instance. 

For the time being I simply reverted to manually retrieving the shared preferences rather than injecting them. 

I really need to upgrade the preferences to fragments at some point anyway, which will be a good time to look into getting the injection working once again.

 

Overall a fairly painless upgrade.

Have a browse on https://github.com/davespanton/Nutbar to see it in more detail.

 

 

Switching my Android environment from Eclipse to Intellij IDEA

I've been using Eclipe for Android development pretty much since Android's release. I'm generally pretty happy using Eclipse; finding it always works well for small Android projects. 

More recently I've been using Maven with Android to better co-ordinate working with different libraries. Setting up Maven to work with Android in Eclipse was a bit of a pain, but not too difficult. 

Earlier this week I upgraded my Android SDK to r15; which promptly broke my project in Eclipse with a cryptic "Conversion to Dalvik format failed with error 1". Google reveals a number of people experiencing similar issues, but none of the suggested solutions seemed to work.

Another tack was to move from my old Galileo installation to a shiny new Indigo one and see if that helped. Got it all set up okay, and the old error went away; to be replaced with an out of memory error whenever I tried to launch.

Strangely enough everything still worked fine using Maven from the command line.

At this point I decided maybe Eclipse and it's various plugins were the weak link. Intellij IDEA seemed like it would be worth trying and the setup process was suprisingly straightforward. 

Beyond downloading and unzipping the community edition I had to setup the Sun JDK and JRE (https://help.ubuntu.com/community/Java) instead of using the OpenJDK. I also had to setup an M2_HOME environment variable to point to my Maven install. Both of steps tasks were spelled out by the IDE. 

Within about 15 minutes of downloading I had the project error free, building and running on a device. 

So for developing in the new environment has been good. I'll post an update once I've done a bit more with it.