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.