Migrate from Eclipse to Android Studio without pain

I advise you to read entire post and then start working on migration from Eclipse to Android Studio. You can also try to move along with migration while reading it. I think it’s most efficient way of doing this.

In the beginning I need to mention that in this post I use Eclipse Kepler 4.3 with ADT 22.3.0Gradle 1.10 and Android Studio 0.4.4 you need to keep that in mind because last two of these projects are still in early development process and there are many problems you may encounter that are specific to software version that you’re currently using.

Export projects from Eclipse

The best way to export projects from eclipse is to follow guide on android developers website but at the time of writing this post gradle build files generated by ADT plugin was a bit outdated so you will probably came across some errors. First of all…

Most common error – Gradle version not supported

Android Studio will probably will greet you with similar error message in event log:

You are using Gradle version 1.6, which is not supported. Please use version 1.9.

The reason why this error occurs is because generated  build.gradle files tells Android Studio to use older version of Android Gradle Plugin. So let’s open the file build.gradle which was created by Eclipse in root of your project (if you exported app which has some library project dependencies open build.gradle located in the very root of your multiproject setup) and modify it to look something like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
    }
}

After that your Android Studio Copy uses correct version of Gradle. Choose File -> Settings -> Gradle and mark “Use local gradle distribution” and enter path to your Gradle home. Click apply and rebuild your whole project.

Still not working – missing Android API error

You may also get error about missing API target. To resole this kind of  error just open Android AVD manager and download missing API level. This error is quite natural and won’t occur if like me you were using the same Android SDK directory for eclipse and Andoid Studio.

Manifest error – Could not find element “Application”

I came across this error while I was trying to import really large android project set with many library projects. The reason of this error is that Eclipse doesn’t require every android project to have an <application/> tag included in AndroidManifest.xml file. Unfortunately  for us Android Studio does require it. To solve this issue just add empty <application/> tag to project manifest that has an error.

Manifest merging min/targetSdkVersion

This is another error which I encounter in my large project set. The first reason for this error was that min and target SDK versions secified in build.gradle and AndroidManifest.xml were different for my project exported from Eclipse. If you already fixed that in all of your projects and you still see this error there is another reason. I found out that if some of libraries (AndroidStudio calls them modules) has incompatible SDK level with another module (that it depends on) in workspace an error will still be present.

Library project error

This error is really rare and happens only if Eclipse somehow don’t see your project as library and won’t generate “android-library” attribute in build.gradle. To solve it just change apply plugin  line (probably first line in your library build.gradle) to look like:

apply plugin: 'android-library'

Hopefully after all that you’ll enjoy building your project in your new favourite IDE 😉

Leave a comment