Telerik blogs
A few weeks ago Google released Android Studio 2.0 Beta, and it's full of great improvements for Android developers. The pile of improvements includes faster emulators, much faster builds (about 2-2.5 times faster) as well as Instant Run. The Instant Run is particularly interesting as it allows an instant refresh of the deployed application as you apply changes to the code of that application. That’s super cool as it will save you quite a lot of time in building and deploying your apps as you develop them. 

So, taking just these features into consideration, we were very interested to try out the new Android Studio 2.0 Beta and see how our UI for Android suite behaves there. I am happy to inform you that UI for Android works flawlessly in Android Studio 2.0 Beta. You not only can use UI for Android in Android Studio 2.0 as before, but the property changes you apply to the UI for Android components will be instantly reflected on the already deployed app using the Instant Run feature. We had a very fun time testing it out and I encourage you to do the same.

Here is a step-by-step breakdown of what you should do to play with the demo app of UI for Android inside Android Studio 2.0 and see the Instant Run feature in action:

  1. Get Android Studio 2.0 Beta from here.
  2. Start a new instance of Android Studio. Choose Open an existing Android Studio project then open the build.gradle file inside the Examples\AndroidStudio folder. As outlined in the UI for Android documentation, make sure you have copied all files from the Examples\AndroidStudio subfolder to a location suitable for you that does not require Administrator access to write to, or that you are running Android Studio as administrator.
  3. As discussed in this StackOverflow thread and described in the Instant Run documentation, the build tools have been moved from mavenCentral to jcenter, so open the build.gradle file and change your buildscript block from:
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
        }
    }
    to:
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
        }
    }
  4. This will prevent you from getting the Error:Could not find com.android.tools.build:gradle:2.0.0-alpha2 error when you try to update your project to work with Instant Run (as explained in step 7).
  5. Click the Sync Now action link as prompted: android-studio-sync-now
  6. Renderscript with version 21 or above does not seem to be supported by the latest version of the build tools as discussed in this GitHub issue. So, change the renderscriptTargetApi to 20 in order to avoid this potential error: Error:A problem occurred configuring root project 'AndroidStudio'. > Renderscript support mode is not currently supported with renderscript target 21+
  7. Now that we've changed the buildscript block and the renderscriptTargetApi version, we're ready to really update the project for Instant Run. Go to File >> Settings >> Build, Execution, Deployment >> Instant Run and click the Update Project action link to make the project good for the Instant Run feature. Note that, as discussed in the Instant Run documentation, some simple changes do not require any kind of restart. However, more complex changes—like the change of a string resource, or change in the UI—require an Activity restart. Note that this will not restart your whole app, but just the activity in order to refresh the UI. So, check the Restart activity on code changes checkbox.android-studio-instant-run
  8. Build and run the project. Here is how I made a few simple visual changes to the Chart for Android and how this was immediately reflected on the emulator: http://screencast.com/t/IaPMFkxa9qB. Nice, huh?
Feel free to get the latest UI for Android bits from Your Account [Trial|Dev] and try them with Android Studio 2.0. We'll keep our fingers crossed for a soon-to-come official Android Studio 2.0.

Happy coding!

About the Author

Nikolay Diyanov

Diyanov is the Product Manager of the Native Mobile UI division at Progress. Delivering outstanding solutions that make developers' lives easier is his passion and the biggest reward in his work. In his spare time, Nikolay enjoys travelling around the world, hiking, sun-bathing and kite-surfing.

Find him on Twitter @n_diyanov or on LinkedIn.

Comments

Comments are disabled in preview mode.