Wednesday, December 31, 2014

MyNotes: Migrating to Android Studio

Converting to Android Studio is pretty easy.

The first step is in the migration is open the Android Studio and import the project:

Once the import completes, you will notice that the structure is a little different than eclipse.  Android Studio uses modules instead of projects.  In the case my import, the top-level module is named "app".  I changed this to MyNotes because I like to use library projects and it easier to manage the modules with more descriptive names.

Underneath that the MyNotes module, you will notice that things are organized a bit differently.

The first big difference is that the project consists of modules.  I only have one at this point, MyNotes.  Under that module, the directory structure isn't flat.  By default, the import only creates the main folder.  The normal android project structure all exists under this folder.

Eventually, main will get a sibling folder that will contain the unit tests, but that is another step.

The other big difference is that build tool here is Gradle.  There is definitely a learning curve with Gradle.  Once I got use to it, I learned to appreciate it.  You will notice that there are three gradle files in the project by default: settings.gradle, the project build.gradle, MyNotes module build.gradle.
The settings.gradle and project build.gradle will not change much.  Most changes occur in the modules gradle file.

Which brings us to the first modification to MyNotes gradle file.  Since the oldest build I plan to support is Ice Cream Sandwich, I updated the gradle file to support that as the minimum SDK and to use Lollipop as the target.

Anytime you modify any gradle file be sure to do a gradle sync or a tools->android->sync project with gradle to ensure the changes propagate. The tools->android->sync project with gradle is actually handy to run anytime you get weird build issues.  It doesn't happen very often anymore, but it is a handy trick to know.

Now that everything is compiling again, we can call the migration good.

You can find the commit for these changes here.

No comments :

Post a Comment