Thursday, December 11, 2014

I've been tracking the Android Studio releases from afar for awhile and have been looking for an excuse to truly give it a shot. Besides the fact that Java 7 for IntelliJ wasn't really supported on the Mac for some time, the transition from the Eclipse build system to Gradle seemed a bit invasive.

One of the biggest barriers in my mind was migrating my Git repository to the new Gradle structure without losing file history. Android Studio will migrate an Eclipse project to an Android Studio, Gradle-based one, which involved moving a number of folders as well as replacing Eclipse- with Gradle-specific configuration files. I wanted to use the Android Studio migration tool but was unsure whether Git would identify these changes as file moves or treat them as entirely new files, which would make tracking file history more cumbersome.

Some have found that Git will identify these files as simply moved/renamed, but unfortunately I did not experience that. Instead, I found that I could run the migration tool in a separate location and manually recreate the moves on the original repository. Here's how I did that, in case anyone else is trying the make the move as well.

Create a new branch in the Eclipse project location. This will make it easier to delete any changes if migration gets messy.

Start the Android Studio migration tool. To get it running, I closed any open Android Studio project, and the wizard popped up. I then chose to import a non-Android Studio project and pointed to the Eclipse project location. For the new project, I chose a distinct outside folder location.

Migrate the project! There were some errors upon actually building the project, but at least for me the migration itself went smoothly.

Mirror the major folder moves. Back in the original Eclipse project location, I started moving folders via git to mirror the new structure. The key is that there are really only a few folders to move, so it's not as painful as it looks. Here are the main commands I ran, with help from this post:mkdir -p app/src/main/javagit mv src/com app/src/main/javagit mv res app/src/maingit mv assets app/src/maingit mv AndroidManifest.xml app/src/main"src/org" can be changed to whatever your source sub-root folder is, and "assets" or other folders may need to be in/excluded according to your project files.

Commit these changes in the new branch. Now they are ready to be picked up in your new Gradle-based project!

Copy the Eclipse project's .git folder into the new Gradle-based project location. This will make the Git repo with all the major moves available in your Gradle location, including the new branch where all the dirty work is being done.

Turn on VCS for the new project. Android Studio has a dedicated VCS menu with the option to turn on various versioning systems. Once it's activated, you can show changes and confirm that Git sees all those moved files as being in the right place.

Add all the new Gradle-based files. The nice thing about using the Android Studio VCS is that it knows not to show a bunch of Gradle build files that shouldn't be version controlled. It also deletes a bunch of Eclipse-specific project files from Git simply because they weren't migrated. The challenge however is that it doesn't by default offer to add all the files you do in fact need. Here are the files that appear to be key, which I learned from viewing the Android Samples project structure:app/build.gradlegradlebuild.gradlegradlewgradlew.batsettings.gradle

Commit all changes to Git. If you've pushed them, you should be able to pull them on another machine right from within Android Studio to access your project there.

From my brief taste of Android Studio so far, it's been quite a treat!

Notable Quotable

"This club with a shortage of ego and an excess of character ascended to baseball's throne in the way it preferred, with a collaborative performance." (Chris Haft, on the San Francisco Giants' 2012 World Series victory)

"In a society that craves results now, in a world that demands excellence every day, head coaches rarely are allowed the time they need to grow into the job and master it. Reminders of it come every year at this time. Head coaches are fired, head coaches are hired and the coaching carousel spins without producing in the ways NFL owners had hoped." (Adam Shefter, on the "coaching carousel" of rapid coaching firing/hiring after the season)

"A perennial danger among contemporary students of the New Testament is to overlook the two-thousand-year history of debate and interpretation generated by these twenty-seven books. The pressure to be up-to-date with the voluminous contemporary literature, combined with the penchant endemic to twenty-first-century Western culture to revere the innovative, even the faddish, and be suspicious of the traditional, conspires to blind us to our connections with twenty centuries of Christian readers." (Carson DA & Moo DJ, An Introduction to the New Testament, p. 31)