Android Studio 2.0 is out

Google released the second version of the official Android IDE a few days ago and it looked like a good incentive to get back to some Android programming! I took a few hours last weekend to update my SDK and give a try to this new shiny environment.

New features

This release is based on IntelliJ 15, and beyond the new features shipped in that version, Android Studio 2.0 brings the following improvements.

Instant Run

This is the new big thing. In order to reduce overhead in the edit - build - run cycle, source code changes are now pushed incrementally to the target emulator or physical device, provided they are running API 14 (Ice Cream Sandwich) or higher. The run button has changed accordingly and triggers incremental build by default, but you can still ask for a full rebuild if necessary.

Instant run button

There are now four kinds of build, depending on the kind of changes applied since the last time code was pushed to the device:

  • Hot swap: the application continues running and the new code is pushed transparently. For now, this only works when changing the implementation code of existing methods. By default, Android Studio restarts the current Activity after a hot swap, but you can disable this behavior.
  • Warm swap: the application continues running but the current Activity is restarted (and there is no way to prevent it in this case). For now, this only applies to changes in resource files.
  • Cold swap: the entire application is restarted. This applies in most cases: changes in class signatures, annotations, class hierarchies, layout elements using dynamic resource IDs... Although this is a bit slower than hot and warm swaps, it is still way faster than a full APK deployment.
  • Fresh deployment: the entire application is stopped, a new APK is compiled and deployed, and the new application is started. This is the old behavior, and it now only happens when editing Manifest-related source code.

Emulator

The Android Emulator also got a big revamp and now allegedly runs up to 3x faster than the previous version, thanks to a better use of the host hardware. This, along with the improved performance of adb push and the Instant Run feature, aims at making developing for Android faster and smoother.

More visible is the new Emulator toolbar with controls to switch on/off or rotate the device and a shortcut to the new Settings screen, making the features of the DDMS Emulator Control panel more accessible.

Instant run button

Cloud Test Lab Integration

Cloud Test Lab features are now integrated directly into Android Studio, allowing to trigger automatic tests on a wide range of physical devices running in the cloud, directly from the IDE.

App Indexing Code Generation

Android Studio can now automatically generate and test indexable URLs to insert in your application to improve its visibility on Google Search.

GPU Debugger Preview

The Android debugger ships with new features for developers of OpenGL ES based apps, including frame-by-frame debugging and access to the GL state.

Upgrade to Android Studio 2.0

In order to switch to Android Studio 2.0 and use these features, you first need to upgrade the IDE. The easiest way is to use the embedded upgrade tool (in Android Studio, Help -> Check for update), but if you want to do a fresh install, you can download it from here. If you are targeting Android N and also want to use Java 8 features, you should follow these instructions and go directly to the Android Studio 2.1 Preview, but part of the Instant Run feature will not be available.

You also need to update your SDK if necessary, using the SDK Manager or directly from Android Studio when prompted, then open an Emulator. This will trigger the update of the virtualization platform and the Emulator itself.

Finally, you need to update the Gradle Plugin version in all of your projects. Your project-level build.gradle should now specify classpath 'com.android.tools.build:gradle:2.0.0' as dependency.

My thoughts

A few years ago, developing on Android was a real pain. The official IDE was based on Eclipse, very slow and full of bugs. The shift to Android Studio, based on IntelliJ, was a big relief. Since then, Google has dramatically improved the edit - build - run cycle, and big steps forward have been made with the continuous improvement of live previews of layouts directly in the IDE.

Now, Instant Run is a game changer because it extends this "instant feedback" feeling to the entire development chain. Deploying small code changes really is instantaneous, allowing to use the Emulator for fast trial and error cycles, even on layouts. In all the situations I faced, Instant Run deployed my changes faster than with a full rebuild. The Emulator itself feels a lot swifter and seems to have benefited from noticeable performance improvement.

I haven't had the chance to test the other new features yet, but you can find more information about them on the Android Developers Blog.