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

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

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=iand 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.

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.

Android restaurant 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”.

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”.

ADT's Export project dialog box

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.

01 apply plugin: 'android'

02
 

03 dependencies {

04   compile fileTree(dir: 'libs', include: '*.jar')

05  compile project(':google-play-services_lib')

06 }

07
 

08 android {

09    compileSdkVersion 20

10    buildToolsVersion "20.0.0"

11
 

12    sourceSets {

13   main {   main {
     

14  manifest.srcFile 'AndroidManifest.xml'
          

15    java.srcDirs = ['src']
        

16    resources.srcDirs = ['src']
        

17  aidl.srcDirs = ['src']
          

18   renderscript.srcDirs = ['src']
         

19   res.srcDirs = ['res']
         

20  assets.srcDirs = ['assets']
          

21   }
     

22
 

23  // Move the tests to tests/java, tests/res, etc…
      

24  instrumentTest.setRoot('tests')
      

25
 

26   // Move the build types to build-types/<type>
     

27   // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, …
     

28   // This moves them out of them default location under src/<type>/… which would
     

29  // conflict with src/ being used by the main source set.
      

30   // Adding new build types or product flavors should be accompanied
     

31    // by a similar customization.
    

32   debug.setRoot('build-types/debug')
     

33  release.setRoot('build-types/release')
      

34    }

35 }
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).

the import project option in Android Studio

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.

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.

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.

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.

For more such Android resources and tools from Intel, please visit the Intel® Developer Zone

Source: https://software.intel.com/en-us/android/articles/embracing-the-new-android-app-development-environment-android-studio-beta

Promotion
Digit.in
Logo
Digit.in
Logo