Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Android

Embracing the New Android App Development Environment – Android Studio (Beta)

5.00/5 (3 votes)
1 Jun 2015CPOL7 min read 10.6K  
This article introduces Android Studio (Beta), the new Android integrated development environment (IDE), which will eventually replace the Eclipse ADT Bundle.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

Intel® Developer Zone offers tools and how-to information for cross-platform app development, platform and technology information, code samples, and peer expertise to help developers innovate and succeed. Join our communities for Android, Internet of Things, Intel® RealSense™ Technology, and Windows to download tools, access dev kits, share ideas with like-minded developers, and participate in hackathon’s, contests, roadshows, and local events.

Abstract

This article introduces Android* Studio (Beta), the new Android* integrated development environment (IDE), which will eventually replace the Eclipse* ADT* Bundle. As a use case, this article discusses the flow of moving an Android project currently developed using Eclipse ADT to using Android Studio.

Caution: When this article was written, Android Studio was still in Beta. You may encounter not-yet-implemented features and bugs. If you are not comfortable with a Beta product, you may want to stay with the development environment you are currently using, such as the ADT Eclipse.

Introduction

In the past several years, Android had been encouraging and enabling developers to use the Eclipse ADT (Android Developer Tools) Bundle as the app development environment. This was changed in recent months after Android Studio (Beta) was announced and available for download. In the past several months, we have seen this new IDE improving. As the Android developer community was informed, Android Studio will eventually be the official Android IDE. For an Android developer currently using ADT, it is good to proactively migrate to the Android Studio IDE since, as we will show you in this article, the migration is fairly straightforward.

Unlike the ADT Bundle, which is based on Eclipse IDE and the Apache Ant* build system, Android Studio is powered by IntelliJ* IDEA and the Gradle* build system. Although the underlying components and technologies are very different, Android provides tools and process flows to support the transition from using ADT to Android Studio.

The discussion in this article is based on JDK version 1.8.0_25Android Studio (Beta) version 0.9.1, and ADT version 23.0.2, on a 64-bit Windows* 8.1 system.

Installation and Setup

To install and run Android Studio, you are required to have JDK 6 or above. To see if you have the required version of JDK, open a Command Prompt window, and enter "javac -version" as your command. You should see a javac version number. Make sure it is greater than 1.6, otherwise go to http://www.oracle.com/technetwork/java/javase/downloads/index.html to download and install a proper version of JDK. You may need to add a system environment variable "JAVA_HOME" with the JDK installation directory in the value field.

There is no Android SDK or SDK tools bundled in the Android Studio download. You may choose to copy an existing Android "sdk" folder from the IDE you were using; for example, from the ADT installation directory, to the same directory you are going to install the Android Studio, such as C:\android. If there is no Android SDK currently on your system, you may visit https://developer.android.com/sdk/index.html?hl=i and go to the "Get the SDK for An Existing IDE" section to download a copy of standalone SDK tools for Windows. For convenience, you may have the SDK Tools installer put everything under the C:\android\sdk folder.

To download Android Studio Beta, visit the official download page:

https://developer.android.com/sdk/installing/studio.html

The package is a .zip file. Simply extract the .zip file to a folder, for example, C:\android. To launch Android Studio, simply go to C:\android\android-studio\bin and run "studio64.exe".

If things go smoothly, you will see an Android Studio start window similar to Figure 1.

Image 1

Figure 1 - Android Studio Start Window

Migration from Eclipse ADT to Android Studio

This article makes the assumptions that 1) you have been an experienced Android app developer, and 2) you have been using the ADT on Eclipse, the most popular Android app development environment. With the advent of Android Studio, you may want to migrate your current projects under development or under maintenance from ADT to Android Studio. In our case we have a restaurant business app (Figure 2) which explores many advanced features provided by Android SDK, such as animation, sensors, Geolocation, and NFC. The app was developed using ADT.

Image 2

Figure 2 - A Restaurant Android business app

We will provide a step-by-step guide on how to migrate a project to Android Studio, so that its future development can be continued under the new development environment.

Exporting the Gradle Build Files in ADT Eclipse

You may have been told that in using Android Studio, you can directly import an ADT project. However based on our experiments, exporting the Gradle build files from your ADT project then importing the generated build files into Android Studio is a more reliable way.

On your ADT Eclipse IDE (Figure 3), right click at the open project, which in our case here is the "RestaurantApp" project in the "Package Explorer" window, and select "Export".

Image 3

Figure 3 - The Eclipse ADT IDE

In the "Export" dialog box, select "Android", then "Generate Gradle build files" (Figure 4). The export dialog boxes will guide you through the process of generating Android Studio build files. On the final step, you will need to check the "Force overriding of existing files" box, then press "Finish".

Image 4

Figure 4 - In ADT's Export project dialog box, select the option to generate Gradle build files

After completing the export process, we can see there is a build.gradle file generated at the project root "RestaurantApp" directory. This is the file we will use to import the project in Android Studio.

As we have mentioned, while ADT Eclipse uses Apache Ant to handle the project build, Android Studio adopts a different build system called Gradle. In Gradle, project builds are driven by build scripts, such as the build.gradle files. Build scripts are written in a dynamic language called Groovy*. We may take a look at the build.gradle file (Code Example 1) to get some ideas. The most important key is the first line, which applies the "android" plugin to the project. The plugin will add a number of tasks to the project to accomplish the build requirements.

C+
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services_lib')
}

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}
Code Example 1 - The build.gradle file generated for the RestaurantApp project **

After exporting the Gradle build files, we can close the project and exit ADT Eclipse.

Importing Projects to Android Studio

Now we start Android Studio, and on the Start window, select the "Import non-Android Studio Project" (Figure 5).

Image 5

Figure 5 - The import project option in Android Studio Start window

On the next screen, we browse to the RestaurantApp project folder, and select the build.gradle file generated by ADT Eclipse (Figure 6) and click OK.

Image 6

Figure 6 - Select the Gradle file to import

That is it! In Android Studio, we now have our RestaurantApp project (Figure 7). We can continue our development under the new IDE.

Image 7

Figure 7 - The imported project in Android Studio

Start a New Android Studio Project

After we become familiar with Android Studio, we can see is it is a powerful tool for developing apps running on all kinds of Android form factors, which include phones, tablets, Android TVs, and Android Wear (Figure 8).

So, starting to use this tool now provides great advantages for Android developers.

Image 8

Figure 8 - Android Studio supports the development for new Android form factors

Current Limitations

One thing we should note is that Android Studio is still in Beta. Some features are still under development and not yet included. For example, at the time when this article was written, NDK support had not yet been integrated in the tool, but as Android promises, it will be included soon.

Other Related References

About the Author

Miao Wei is a software engineer in Intel’s Software and Services Group. He currently works on the Intel® Atom™ processor scale enabling projects.

**This sample source code is released under the Intel Sample Source Code License Agreement

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)