How to update from Dart & Henson 2 to the latest version(3.0.1)

Alejandro Rios
Sep 9, 2018 · 3 min read
Easy steps indeed, image link

Hey all!!!, this article will explain you in a very simple way(i hope) how to migrate the Dart & Henson library from 2.0.2 to 3.0.1 version, taking Chandrasekar Kuppusamy (@takeoffandroid) project as example, each step described below will be a commit message in the final code.

But… What is Dart & Henson?

Dart and Henson is an Android dependency injection library created by a team of Groupon developers, the idea is to help you with the Intent data passing in a more organized way, here are two articles to see more details about it:

let’s begin….

The first thing that we need to do is update the libraries to the latests version obviously, the Gradle build works fine but if you run Build->ReBuild project you’ll see the horror!!!!

Noooo…….

You’re going to see that the code doesn’t compile because the Dart & Henson library update changes its way of use, so….. What now? Let’s start with the creation of the Navigation model, we need to go to Menu->File->New Module and select Android Library as the new module.

Setting the module

According to the library’s README file, the module must follow a naming convention including the package name, AS will create the empty module after that we need to add the libraries on the module’s build.gradle and create the navigation model.

Note: in the manifest of the module replace the package with package="com.f22labs.darthensondemo_navigation"

Model declaration

As you can see Dart & Henson update replace @InjectExtra with @BindExtra and recognizes this as a navigation model using the @DartModel annotation, the @Nullable works the same as before.

At this point we have just update the libraries and declare the navigation model, now we’re going to adjust Dart to use the model as the app need it, for this, we’re adding the module implementation in the app’s build.gradle so we can use it, after that, replace the @InjectExtra variable declarations with the navigation model declaration and also change Dart.inject(this) for Dart.bind(this) as the new version requires

We are almost done...

Now to finish change the Henson implementation update for the new version, go back to the app’s build.gradle file add the Henson-plugin and also include it to the classpath of the project’s build.gradle

build.gradle of the project
Version 2 of the app’s build.gradle

The new version of Henson change the way the intent builder is created, according to the documentation…

Based on the navigation model, henson will create an intent builder for the described class (remember the name of the activity / service can be deduced from the FQN of the model). It creates also some useful wrapper around them.

basically replaces this

Intent intent = Henson.with(MainActivity.this)
.gotoDetailsActivity()

with this:

Intent intent = HensonNavigator.gotoDetailsActivity(this)

if all goes well, you’ll see the .gotoDetailsActivity appear as a suggestion of the HensonNavigator declaration.

and we are done!!!!.

The full code is available here:

Note: This is my first article (yay!!), any suggestions, claps, comments will be gratefully appreciated 😊

Alejandro Rios

Written by

Android Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade