Gearing up for android studio 2.0

Android studio

 

Hi,

I am gonna talk about setting up android studio 2.0 (currently only preview is available) and some of the new features in this post.

First things first… What is android studio?

If you are an android developer, the above question is useless. Here’s a little info anyway:

  • Google’s IDE for android development.
  • Built in support for Google cloud platform.
  • Flexible Gradle-based build system.
  • Built on top of latest IntelliJ IDEA platform.
  • Multi screen app development.
  • Latest version 1.5.1. (as of December-19,2015)
  • Available on android developer site. http://developer.android.com/sdk/index.html

If you are still using eclipse for android development, this is the right time to switch to android studio.

The one major problem with android studio has been speed. Android studio was slow. Since the early release of this IDE, there has been a lot of changes. Android studio 2.0 is just awesome. It is not released yet, but the preview version is available on canary channel. As of now it is recommended to keep two copies of android studio, you shouldn’t update your current dev environment to studio 2.0 preview. You can (just change the updates channel in IDE) but you shouldn’t.

Almost all the issues I faced are gone in android studio 2.0 preview 5 (released on 14-jan-2016). Awesome features (detailed later in the post).

If you are wondering how to keep multiple copies of android studio in one machine, this will help.

Now once you are done downloading the studio preview from the canary channel, import a sample project or one of your projects or simply create a new one. Few more steps to get the most out of the 2.0 preview:

  • Change the gradle plugin used in your app module to gradle:2.0.0-alpha5′
    • classpath ‘com.android.tools.build:gradle:2.0.0-alpha5’ in dependencies
    • This is required for features like instant run (read on to know more).
  • Download latest android sdk tools from preview channel.
    • This is needed for emulators 2.0 and other cool stuff (bleeding edge stuff as google calls it).

studio_2_0_tools_download_01

  • Change your update dialogue in IDE settings to get updates from canary channel and sdk tools from preview channel.
    • This is optional but set it so that you get the latest updates.
    • To set it. click help->check for updates. In the dialogue that opens click on updates hyperlink.
    • Latest android sdk tools as of now is 25.0.2 rc3.

That’s it you are now all setup for exploring and using the new android studio 2.0 preview.

Here’s almost everything you need to know about android studio 2.0 preview (preview 5 released on 14-Jan-2015):

  • If you have some time please watch this video by google devs. It explains a lotta things.
  • Broadly the new changes are categorized into three categories:
    • Build System
    • IDE enhancements
    • Android emulators

Android Studio has never been faster and developer friendly. Category wise improvements:

  • Build System
    • Improved dx merger (Build tools 23.0.2+, Gradle plugin 2.0+)
      • Pre-dexes dependencies
      • resulting in gradle build being 2.0-2.5 times faster.
      • One of my apps that has 20k+ lines of code used to take 2 min 53 sec to build, now it takes only 23 seconds. So in my case it is more than 6 times faster.
    • New experimental shrinker for debug mode
      • We all use proguard for release. It is awesome. It shrinks, optimizes and obfuscates the code. But we never get its benefit for debug mode. With the new experimental shrinker we can get the shrinking benefit right in debug mode.
      • To enable it just set minifyEnabled to true and useProguard to false in debug build type.
      • overall build deploy cycle is ~1.5 times faster. (Not great but still cool)
    • New protocol for ADB push / pull.
      • huge speed improvement in adb push n pull.
    • Instant Run (My personal favourite, requires Gradle 2.0-alpha5+ and gradlew 2.10)
      • It is process of deploying code changes on the fly without having to build the whole app.
      • You can see your changes in a matter of seconds in an emulator or a connected device.
      • Instant run is available in almost all
        • android versions (4.0+)
        • physical devices
        • emulators (2.0+ of course)
      • Hot swap (supported in 2.0 preview 2+)
        • Swap code changes on the fly
      • cold swap (supported in 2.0 preview 5+)
        • Deploy deltas for code changes that cannot be hot swapped.
        • Not tested this but according to release notes it is supported
      • Freeze swap (supported in 2.0 preview 5)
        • Build changes incrementally even if the app is not running on device or emulator.
        • Not tested this but according to release notes it is supported.
      • I think Instant run deserves it’s own blog post. Maybe later 🙂
  • IDE enhancements
    • Latest IntelliJ 15 support (15.0.2).
      • built on top of IntelliJ 15.0.2 (released sometime in NOV 2015)
    • New GPU profiler (experimental preview).
      • It is available in studio 1.5.1 as well, but with 2.0 preview you can save the entire graphic stream and play it frame by frame in emulator and device to figure out why your Open GL app crashed or ANR.
      • This is also in experimental state, but still very powerful tool for open GL.
    • In built support for Google search deep linking.
      • Deeplinks means how your app comes up in devices’ Google search when your app is installed and when not installed.
      • Deeplinks have been present for a long time now. With studio 2.0 you get one click support for creating deep links.
      • Just open manifest file and click on that yellow bulb icon on left of the editor.
    • Lot of UI improvements.
      • Download it to see the UI improvements.
  • Android emulators
    • I know, lot of us prefer real devices for testing over laggy emulators. But I believe with emulators 2.0 you would prefer emulators over actual device.
    • Completely new UI with extended controls.
      • Control almost every feature of emulated device
    • Drag and drop apks and files to install and copy.
    • Send sms, receive calls.
    • System keyboard support.
      • Directly type in from system keyboard.
    • Finger printing support.
      • If you don’t have Nexus 5X or 6P, you can test finger printing API using emulators 2.0. It features a set of 10 fake finger prints to test the API.
    • Resize emulators.
    • Emulate GPS locations via kml and gpx files
    • android emulator 2_0

 

The mentioned points cover some of the new features introduced in android studio 2.0 preview. One important part that I left out here is the testing support. There is a new way to test various product flavours. I still don’t know much about it, I think it is called hermetic testing. You can test instrumentation and android test simultaneously.

I will cover more on emulators and how Instant Run works in upcoming blog posts.

Stay tuned.

Have questions? Did I miss anything? Shoot below in comments

-Kaushal D (@drulabs twitter/github)

drulabs@gmail.com