Monday, November 23, 2015

Android Studio 2: Much faster and enhanced testing support

Android 2.0 comes with some great new features. Building and deploying apps will become much faster. The new Instant Run feature for example allows you to quickly see the changes you have made.

The new emulator will run much faster and it will come with enhanced testing support. The emulator will support Google Play Services and phone calls, low battery conditions and GPS locations can be simulated. It will support dragging and dropping APK files, just like Genymotion does.

More speed, that is what Android developers need. And with Android Studio 2.0, which is current available as a preview in the canary channel, speed is what we get.



Enable Instant Run

With Instant Run you build and deploy an app to an emulated or to a physical device just once and then as code needs to be changed, it will only take a few seconds before you can see the changes in the running app.

To see the new stuff for yourself you can grab an Android Studio 2.0 copy from the canary channel and enable the Instant Run feature for your existing apps.

From the Android Studio menu choose Preferences (Android Studio for OSX). In the Preferences dialog expand the Build, execution and deployment option and choose Instant run. You probably need to click on the Update project link to enable this new feature. In my case I also had to update the Build tools and to resync the project.


Once you have done that you are good to go. Run and deploy on the app using the Run button.

While your app is running you can modify your code. For example change the text of a toast being displayed in your app. As a small demo I have modified one of the recipes from my book but you can try this with any app of course.

Now you just hit the Run button again. A toast will be displayed to notify you about the changes. Indeed, we do no longer need to restart the activity to see our changes.



Note! Instant Run is a great feature but it is not (yet) supporting all kinds of changes. Some of these limitations are known, such as changing annotations, static fields or methods. Other kind of changes, such as modifications in the layout, should be supported I guess but I was not able to make it work.

It might because the project that I am using for testing this is having multiple flavors? Or it could be because this is just a preview of Android Studio 2.0 and maybe I need to be a little bit more patient and wait for a more stable release.

Conclusion

Android Studio 2.0 is focused on speed and better testing support. I think that is exactly what Android app developers deserve after struggling so many times with speed (in particular with Eclipse in the old less good days) and with the many fragmentation challenges we still have today.

Just like the Android OS itself Android Studio also has become mature and that is great news!

Further reading

No comments:

Post a Comment