Android Studio 3.5 Canary adds “Apply Changes,” an Instant Run replacement
Android Studio 3.5 (currently in the Canary and Dev channels) now features a new way to push code changes to your app and see their effects on the fly without having to restart the app. Dubbed simply “Apply Changes,” it’s the successor to the “Instant Run” feature in previous versions of Android Studio.
Google’s Android Developers Blog says the following about Apply Changes:
Apply Changes lets you push code and resource changes to your running app without restarting your app—and, in some cases, without restarting the current activity. Apply Changes replaces Instant Run with a completely new approach for build optimization. Instead of rewriting the bytecode of your APK during build time, Apply Changes redefines classes on the fly by leveraging the runtime instrumentation supported in Android 8.0 (API level 26) or higher.
In addition, Android Studio now prompts you to decide whether to restart your app or activity when it detects that changes are not compatible with Apply Changes. This extra control should provide you with a more consistent and predictable experience compared to the behavior of Instant Run.
The blog post goes on to list some limitations to the new functionality. For example, the device you’re testing your app on must at least be running Android 8.0 Oreo (API Level 26) and there are certain code changes that will still require your app to restart. As with “Instant Run,” “Apply Changes” will force your app to restart if you’re:
- Adding or deleting a class, method, or field
- Changing the manifest
- Changing method signatures
- Changing modifiers of methods or classes
- Renaming classes
- Changing class inheritance
- Adding or removing a resource
Under “Known Issues,” the blog post states that since Google initially prioritized stability over performance in this new feature, “Apply Changes” will sometimes run more slowly than its forebear feature “Instant Run.” Also, x86_x64 emulator images are not supported, and for debugging purposes, only Android Pie (API Level 28) is supported. You can see the full list of limitations and known issues at the source link below.
For a more detailed description of the difference between “Apply Changes” and “Instant Run,” a Google employee on the Android Studio team had this to say on Reddit:
It does something very, very different. Instant Run had a very specific impact on build, instrumenting each of your classes at compile time to prepare them for being replaced during the runtime with a new version of the class. It also split your APK in several APKs to re-upload your app more incrementally.
Apply Changes does nothing like it. Your APK is very much the same whether you use Apply Changes or not. Instead it relies on new runtime instrumentation capabilities of the ART VM to dynamic reload classes and replace them while the app is running. This is why it requires much newer versions of Android.
“Apply Changes” is expected to eventually replace “Instant Run” in the Beta and Stable channels as Google makes improvements to its performance and stability.
Source: Android Developers Blog
Want more posts like this delivered to your inbox? Enter your email to be subscribed to our newsletter.