Android: From Eclipse to Android Studio

studio_splashWhen Android Studio was published i thought finally Google was stepping up to make a development environment as good as the iOS one, but no, it was only based on Intellij Idea, which is more friendly than Eclipse, but you can not compare it to xCode.

I started to import all my Android apps to Android Studio from Eclipse, to see if I finally uninstall that slow behemoth called Eclipse. The truth is that the import process is quite simple, when importing Android Studio recreates the directory structure, dependencies, etc ... It also creates all new files that involve changing compiler from Maven to Gradle.

But there are many details to consider in order to make the things work fine. Almost everything has to do with "build.gradle" file. There are two files with this name, it is the one within the application. I'm using the Android Studio 0.8.4.

Projects that use external libraries

Android Studio supports libraries as JAR files, AAR libraries, or uncompiled library projects. In the file “build.gradle”, the libraries appear in "dependencies". When importing, the “most famous” libraries are imported as external AAR; for example if you are using the ActionBar Sherlock as local library, the dependence will be imported as external AAR:

'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'

The rest of the libraries are copied to the project folder with its adaptation to Gradle. If you only have an SDK installed, you need to change the “build.gradle” file of these libraries, writing in "compileSdkVersion" the installed SDK version number.
What happens if you do not want these libraries copied in the project folder?, so you want to keep them in their original folders to be used by other applications. This is simple, first, the library has to be adapted to Gradle, a trick is to copy the files from the library that the importer has copied into your project folder to the original folder of the library, as the files are exactly the same but with adaptation to Gradle, and now you can use this library in other Gradle projects. And then modify the settings.gradle file, which lists the external libraries used by the project, but not their original paths. You have to write, for example:

include ':zBarScannerLibrary'
project(':zBarScannerLibrary').projectDir = new File(settingsDir, '../../Android resources/ZBarScannerLibrary/library')
include ':com_ribbonmenu'
project(':com_ribbonmenu').projectDir = new File(settingsDir, '../../Android resources/RibbonMenu-master/com_ribbonmenu')

One of the features of Gradle is the use of the “Manifest Merger Tool", which creates a single file with all the Manifest files of the main project and the libraries. This process can give errors of repeated elements, especially icons, styles and more. To solve this, the Manifest of the main project needs a change, in the tag "Manifest":

xmlns:tools="http://schemas.android.com/tools"

and in the tag “application”

tools:replace="android:icon,android:theme"

writing the elements that give the repeat error.

Projects that use the old Google Maps v1

Change the “compileSdkVersion” value, from the SDK number (by example 19) to:

'Google Inc.:Google APIs:19'

Projects that use the Android support library

You can see an error if the revision number is missed. By example:
You must write

‘com.android.support:support-v4:20.+’

instead of

'com.android.support:support-v4:+'

Projects of Phonegap

Projects previous to version 3 of Phonegap are imported without problems.

For version 3, if you want to keep the original folder structure generated by Node.js, the import process is different, as explained here. But Gradle is no available using this method. Also some libraries like Google Play Services are not linked properly, you must do it manually.


Changing from Eclipse to Android Studio worth it, it's not a radical change, but the development environment is more friendly, less heavy, and has several interesting features, such as "product flavors" that resemble the "products" of xCode; allowing generate different apks within the same project with different icons, assets, code snippets, app ID, resources, etc..
But the device simulators are the same as Eclipse, bad and slow.

2 comments
  • Juan Carlo
    31-08-2014 21:53
    En Phonegap 3, si la app tiene anuncios Admob, no hay manera de compilarla con Android Studio
  • lemo
    01-09-2014 13:19
    A mi me pasa lo mismo del comentario anterior. ¿qué puede ser?
Leave a comment
I have read and accept the Privacy Policy

The comments sent by each user will always be visible in the corresponding post, and will not be used for any other purpose. The user has the right to access, rectify and suppress said comments, as reflected in our Privacy Policy