What’s New in Android Studio 2.0
Android Studio 2.0 was just released – take a quick tour of what’s new! By Huyen Tue Dao.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
What’s New in Android Studio 2.0
20 mins
- Getting Started
- Improved IDE
- IntelliJ Features
- Deep Links Integration
- Unified Unit Tests and Android Instrumentation Tests
- GPU Profiler
- Android Emulator 2.0
- New Interface
- Phone Call/SMS
- Battery and Charging States
- Location Updates
- Better Builds
- Faster Build Speeds
- Faster ADB
- Instant Run
- Where to Go From Here
Better Builds
You might say to yourself, “Okay, a fast emulator is great, but I’m still spending too much time actually building my app. What do I do about that?”
Well, you could train your dog to code. If nothing else, that could get you some YouTube fame :]
The better solution is—as you might have guessed—Android Studio 2.0!
The Android Tools Team has attempted to rev up build and deployment speeds. They have also added a new feature: Instant Run. You’ll explore these improvements in the next section.
Faster Build Speeds
Reporting speed-ups of 2-2.5x for full build times, the Tools Team has made improvements in several areas of the build system. To fully discuss them would be a pretty deep dive, but generally speaking they include:
- Improvements to the
dx
merger.dx
is the build tool that converts Java classes to Dalvik executable format (.dex) files. - A shrinker for debug mode.
- Builds that specifically target connected devices.
For information on builds and the build system in general, check out the docs on android.developer.com.
For more on these build system improvements in particular, check out this session presented at the Android Dev Summit.
Faster ADB
The Android Debug Bridge (ADB) on the emulator has received a push/pull protocol update. When deploying APKs to the new emulator, you will see up to a 5x speed increase.
Instant Run
Wonderfully, Android Studio 2.0 is all about the need for speed. While the Android Tools Team has sped up builds and deployments, they have also tried to reduce the number of times you have to deploy.
To this end, they have introduced Instant Run, which provides pushing of updates—code and resources—to a running instance of your app on a device or emulator without requiring a full reinstall. Obviously, this is a huge time-saver.
Instant Run works differently for different kinds of changes. Currently, there are three ways Instant Run implements updates:
- A hot swap: your app continues to run and uses the changes next time the relevant method is called. This applies to method changes.
- A warm swap: your app continutes to run but restarts the current activity. This applies to resource changes.
- A cold swap: your app restarts but does not reinstall. This applies to structural code changes.
You can try out Instant Run right now in the companion app.
To enable Instant Run, select Preferences \ Build, Execution, Deployment \ Instant Run. Ensure that Enable Instant Run to hot swap code/resource changes on deploy is checked and that Restart activity on code changes is unchecked.
If the companion app is not yet running, launch it by clicking the Run button, and wait for it to launch.
When the app is running, you should see a lightning bolt next to the Run button. The lightning bolt indicates that Instant Run is available.
To test it out, open colors.xml and make the following changes to the colors:
<resources>
<color name="colorPrimary">#455A64</color>
<color name="colorPrimaryDark">#263238</color>
<color name="colorAccent">#2196F3</color>
</resources>
This simply changes the values of colorPrimary
and colorPrimaryDark
, which determine the colors of the status bar and action bar.
Hit the Run button. The screen will flicker, and you’ll see a toast notifying you that the activity restarted. You will also see that the app already shows the colors changes without a full build and install.
Because of the activity restart, you can probably guess that this was a warm swap.
Now open CardViewHolder.java and make the following changes to the onClick
method:
@Override
public void onClick(View v) {
if (mListener == null) {
return;
}
Snackbar.make(itemView, R.string.instant_run, Snackbar.LENGTH_SHORT).show();
mListener.onToggleLocationUpdates();
}
This added code requests that a snackbar be shown whenever someone clicks the START/STOP button on the top card of the companion app.
Hit the Run button. A toast will appear to notify you that Instant Run “Applied code changes without activity restart.”
Can you guess what kind of swap that was?
If you guessed hot swap, give yourself a cookie! :] Instant Run was able to push the changes without even restarting the activity. And if you click the START/STOP button, you can verify that the changes were successfully pushed:
Instant Run can dramatically increase productivity, and dramatically decrease the time you spend browsing the Internet as you wait for your builds to finish and deploy (you’ll have to catch up on funny dog pics later). Beyond that, Instant Run will make your layout and styling more efficient, since you can immediately and directly see how code changes result in UI changes.
Where to Go From Here
There certainly is a lot to learn and try out in Android Studio 2.0 and Android Emulator 2.0! Much of the information about the two comes from the Android Dev Summit presentations, so check out those and other great sessions via the recordings posted on YouTube.
Many of the cool new things in Android Studio 2.0 are works in progress. A great way to keep up with updates, bug fixes and new features is to regularly check the Recent Changes page over at the Android Tools Project Site.
The Android Tools Project Site also contains technical docs on many of the Android Studio features.
If you have any questions or comments, feel free to post your comments below or in the forum!