Sunday, September 21, 2014

Migrate a Project in Github to Android Studio

Android Studio is the IDE of the future for Android development.  Unlike Eclipse, Android Studio and the Gradle build system require a default folder layout for the build system to work out of the box.  If you have stored your project in Github using the Eclipse folder layout, migrating to Android Studio can be a challenge.  This documents how I have done the migration on several projects.  The technic used preserves the Git history as you move the files to the Android Studio folder layout.

Create Empty Android Studio Project

Android Studio will not migrate a project from the Eclipse layout to the Studio format. You will need to do the migration by hand. Creating an empty project will generate some of the Gradle files you will need.  Once you create the project, close Android Studio and rename the project folder.

Create project with Github Checkout



Reopen Android Studio and select the option to Checkout From Source Control.  Enter your Github credintials if you have not already.  The result will be a project with the Eclipse folder layout that will not build and is not tied to Gradle

Move Your Files

Close Android Studio again and return to the command line. Create folders to match the structure of your empty Android Studio project. The folders you will have to create are

app/src/main/java

Use Git to move the Java source files to the app/src/main/java directory

git mv src/org app/src/main/java


Next, move the res folder

git mv res app/src/main


Finally, move AndroidManifest.xml

git mv AndroidManifest.xml app/src/main

Copy Files from Empty Project

Copy these files and directories to the same location in your Github checkout project.

  •  gradle directory
  •  gradle.properties
  •  gradlew
  •  build.gradle
  •  app/build.gradle

Migrating to Gradle Build

 Open the Github project in Android Studio.  The Gradle files will be detected and a popup will ask you if you want to migrate to a Gradle project. Click the link and the project will be updated.  If your project will still not build, you may need to add dependencies for libraries such as Appcompat in the app/build.gradle file.