Tag Archives: live edit

Android Studio Hedgehog is stable

Posted by Sandhya Mohan, Product Manager

Today, we are thrilled to announce the stable release of Android Studio Hedgehog 🦔 : The official IDE for building Android apps!

In this Android Studio release, we have upgraded the IntelliJ platform to 2023.1, with features designed to improve app performance and battery life, make it easier to upgrade applications to the latest Android version, and make it faster to develop using Jetpack Compose. Read on to learn more about how Android Studio Hedgehog can help supercharge your developer productivity.

App performance

Android vitals in App Quality Insights

In addition to helping you investigate crash reports for apps instrumented with the Firebase Crashlytics SDK, App Quality Insights now also includes Android vitals data from Google Play Console. With Android vitals, you can see crash reports for any app you publish to the Google Play Store without requiring additional instrumentation in your app. You can view Android vitals issues, filter them, and see crash insights from Play to quickly understand and resolve the cause of a crash, and jump from stack trace to code all from the App Quality Insights tool window. Learn more.

Note: If you don't have permission to view your app in the Play Console, request that the app admin share read-only access to only app quality information, by clicking Users and permissions > View app quality information (read-only) in the Play Console.

Screengrab of Android Vitals data in App Quality Insights
Android Vitals data in App Quality Insights

Power Profiler

The new Power Profiler shows power consumption on devices. It segments the power consumption information by subsystems called "Power Rails". This helps you visualize the correlation between power consumed and the actions occurring in your app. This approach of directly measuring power consumption differs from the legacy Energy Profiler, which only used a model to estimate energy consumption.

By understanding this information, you can potentially identify and fix power consumption issues in your app by running A/B tests to compare the power consumption of different algorithms, features or even different versions of your app.

Apps which are optimized for lower power consumption lead to an improved battery and thermal performance, eventually leading to an improved end user experience. Power Rails data is available on Pixel 6+ devices running Android 10+.

Example of power consumption in different power rails.
Example of power consumption in different power rails.

Coding productivity

Target Android 14 using Android SDK Upgrade Assistant

The SDK Upgrade Assistant provides a step by step wizard flow to help developers through targetSdkVersion upgrades. It pulls documentation directly into the IDE, saving you time and effort.

Android Studio Hedgehog adds support for upgrading projects to Android 14 (API Level 34). We’ve also added additional relevance filters so that unnecessary steps are removed — and in some cases, the upgrade assistant will pinpoint exactly where in code the changes need to be made.

Screengrab of Android SDK Upgrade Assistant
Android SDK Upgrade Assistant

New UI updates

In the Giraffe release, we launched a new UI for the IDE. This reimagined theme reduces visual complexity and provides easier access to essential features, resulting in a more modern and clean look and feel. We’ve listened to your feedback and, in Hedgehog, we’ve added updates for compact mode, vertical and horizontal splitting, and project tabs for Mac OS. If you have not yet tried the new UI, we encourage you to do so.

Screengrab of Compact mode in the New UI
Compact mode in the New UI

Device mirroring

You can now mirror your physical Android device in the Running Devices window in Android Studio. While mirroring your device's display directly via ADB over USB or Wi-FI to Android Studio, you can execute common actions such as starting and interacting with apps, rotating the screen, folding and unfolding the phone, changing the volume, and more – directly from within Android Studio. Learn more.

Moving image demonstrating device mirroring in the running devices window
Device Mirroring in the Running Devices window

Embedded Layout Inspector

You now have the option to run the Layout Inspector directly in the Running Devices tool window while running your app on an embedded virtual device or mirrored physical device. This opt-in feature significantly improves performance of Layout Inspector, conserves screen real estate, helps organize your UI debugging workflow in a single tool window, and improves speed while inspecting your layout. In embedded mode, you can show a view hierarchy, inspect the properties of each view, navigate to code using “deep inspect” mode, and access other common Layout Inspector features. Enable it through Settings > Experimental > Layout Inspector

Screengrab showing Embedded Layout Inspector
Embedded Layout Inspector

Live Edit updated manual mode shortcut

Live Edit has a new default shortcut for manual mode for: Control+\ (Command+\ for macOS). Manual mode is helpful in situations where you want to have precise control over when updates are deployed to the running application. For more information, see the video clip in Live Edit for Jetpack Compose.

Compose tools

Compose Preview’s Gallery Mode

Gallery mode is a new mode in Compose Preview that lets you focus on one Preview at a time to conserve rendering resources. Use Gallery mode when iterating on UI and switch to other modes (Grid or List) when you need to see UI variants.

Moving image of Compose Preview's Gallery Mode
Compose Preview’s Gallery Mode

Compose State information in Debugger

When setting a breakpoint on a Composable function, the debugger now lists the parameters of the composable and their state, so you can more easily identify what changes might have caused unexpected recompositions.

Screengrab of Compose State information in Debugger
Compose State information in Debugger

Compose Multipreview templates

Android Studio Hedgehog includes support for the latest annotations added by the Compose Multipreview API, allowing developers to render common layout scenarios side-by-side while working with the Compose Preview.

The new annotations added include: @PreviewScreenSizes, @PreviewFontScales, @PreviewLightDark, and @PreviewDynamicColors

Screengrab of Compose Multipreview templates
Compose Multipreview templates

Build tools

New macro to specify JDK path

A new macro, #GRADLE_LOCAL_JAVA_HOME, makes it safer and easier to specify the Java* home path used for the Gradle daemon (background process) execution for your project by referencing your .gradle/config.properties file. This reduces errors related to incompatible Gradle and project JDK versions, since there is now a single source of truth for your Gradle JDK selection.

Starting with Android Studio Hedgehog, new projects will use #GRADLE_LOCAL_JAVA_HOME by default. Existing projects will automatically be migrated to the new macro after a successful sync, unless you're already using a macro like #JAVA_HOME.

[Windows-only] Minimize the impact of antivirus software on build speed

The Build Analyzer informs users if antivirus software may be impacting build performance. This can occur if antivirus software, such as Windows Defender, is performing real-time scanning of directories used by Gradle. Build Analyzer recommends a list of directories to exclude from active scanning, and, if possible, provides a link to add them to the Windows Defender folder exclusion list.

Use Firebase Test Lab devices with Gradle Managed Devices

Gradle Managed Devices can now target Firebase Test Lab devices, and you can utilize it to run your automated tests at scale. Use Gradle Managed Devices to select from a wide range range of both physical and virtual FTL devices, with support for test sharding for accelerated execution time. To use FTL devices, you need Android Gradle Plugin 8.2 with the latest Alpha version of the Firebase Test Lab Gradle plugin. Learn more.

Download Android Studio today!

Now is the time to download Android Studio Hedgehog to incorporate the new features into your workflow. As always, we appreciate any feedback on things you like, issues, or features you would like to see. If you find an issue, please check the known issues and file a bug if needed. Remember to also follow us on X (formerly known as Twitter), Medium, or YouTube for more Android development updates!


*Java is a trademark or registered trademark of Oracle and/or its affiliates.

Deep dive into Live Edit for Jetpack Compose UI

Posted by Alan Leung, Staff Software Engineer, Fabien Sanglard, Senior Software Engineer, Juan Sebastian Oviedo, Senior Product Manager
A closeup look into how the Android Studio team built Live Edit; a feature that accelerates the Compose development process by continuously updating the running application as code changes are made.

What’s Live Edit and how can it help me?

Live Edit introduces a new way to edit your app’s Jetpack Compose UI by instantly deploying code changes to the running application on a physical device or emulator. This means that you can make changes to your app’s UI and immediately see their effect on the running application, enabling you to iterate faster and be more productive in your development. Live Edit was recently released to the stable channel with Android Studio Giraffe and can be enabled in the Editor settings. Developers like Plex and Pocket Casts are already using Live Edit and it has accelerated their development process for Compose UI. It is also helping them in the process of migrating from XML views to Compose.


Moving image illustrating Live Edit in action on Android Studio Hedgehog
Live Edit in action on Android Studio Hedgehog

When should I use Live Edit?

Live Edit is a different feature from Compose Preview and Apply Changes. These features provide value in different ways:

Feature

Description

When should I use it?

Live Edit[Kotlin only, supports live recomposition] Make changes to your Compose app’s UI and immediately see their effect on the running application on an emulator or physical device. Quickly see the effect of updates to UX elements (such as modifier updates and animations) on the overall app experience while the application is running.
Compose Preview

[Compose only] Visualize Compose elements in the Design tab within Android Studio and see them automatically refresh as you make code changes. Preview individual Compose elements in one or many different configurations and states, such as dark theme, locales, and font scale.
Apply Changes

Deploy code and resource updates to a running app without restarting it—and, in some cases, without restarting the current activity. Update code and resources in a non-Compose app without having to redeploy it to an emulator or physical device.

How does it work?

At a high level, Live Edit does the following:

  1. Detects source code changes.
  2. Compiles classes that were updated.
  3. Pushes new classes to the device.
  4. Adds a hook in each class method bytecode to redirect calls to the new bytecode.
  5. Edits the app classpath to ensure changes persist even if the app is restarted.

Illustration of Live Edit architechture
Live Edit architecture

Keystroke detection

This step is handled via the Intellij IDEA Program Structure Interface (PSI) tree. Listeners allow LE to detect the moment a developer makes a change in the Android Studio editor.

Compilation

Fundamentally, Live Edit still relies on the Kotlin compiler to generate code for each incremental change.

Our goal was to create a system where there is less than 250ms latency between the last keystroke and the moment the recomposition happens on the device. Doing a typical incremental build or invoking an external compiler in a traditional sense would not achieve our performance requirement. Instead, Live Edit leverages Android Studio’s tight integration with the Kotlin compiler.

On the highest level, the Kotlin compiler’s compilation can be divided into two stages.

  • Analysis
  • Code generation

The analysis performed as the first step is not entirely restricted to a build process. In fact, the same step is frequently done outside the build system as part of an IDE. From basic syntax checking to auto-complete suggestions, the IDE is constantly performing the same analysis (Step 1 of Diagram 1) and caching the result to provide Kotlin- and Compose-specific functionality to the developer. Our experiment shows that the majority of the compilation time is spent in the analysis stage during build. Live Edit uses that information to invoke the Compose compiler. This allows compilation to happen within 200ms using typical laptops used by developers. Live Edit further optimizes the code generation process and focuses solely on generating code that is only necessary to update the application.

The result is a plain .class file (not a .dex file) that is passed to the next step in the pipeline, desugaring.

How to desugar

When Android app source code is processed by the build system, it is usually “desugared” after it is compiled. This transformation step lets an app run on a set of Android versions devoid of syntactic sugar support and recent API features. This allows developers to use new APIs in their app while still making it available to devices that run older versions of Android.

There are two kinds of desugaring, known as language desugaring and library desugaring. Both of these transformations are performed by R8. To make sure the injected bytecode will match what is currently running on the device, Live Edit must make sure each class file is desugared in a way that is compatible with the desugaring done by the build system.

Language desugaring:

This type of bytecode rewrite aims to provide newer language features for lower targeted API level devices. The goal is to support language features such as the default interface method, lambda expression, method reference, and so on, allowing support down to the min API level. This value is extracted from the .apk file's DEX files using markers left in there by R8.

API desugaring:

Also known as library desugaring, this form of desugaring aims to support JAVA SDK methods and classes. This is configured by a JSON file. Among other things, method call sites are rewritten to target functions located in the desugar library (which is also embedded in the app, in a DEX file). To perform this step, Gradle collaborates with Live Edit by providing the JSON file used during library desugaring.

Function trampoline

To facilitate a rapid “per-key-stroke” speed update to a running application, we decided to not constantly utilize the JVMTI codeswap ability of the Android Runtime (ART) for every single edit. Instead, JVMTI is only used once to perform a code swap that installs trampolines onto a subset of methods within the soon-to-be modified classes inside the VMs. Utilizing something we called the “Primer” (Step 3 of Diagram 1), invocation of the methods is redirected to a specialized interpreter. When the application no longer sees updates for a period of time, Live Edit will replace the code with traditional DEX code for performance benefits of ART. This saves developers time by immediately updating the running application as code changes are made.

Illustration of Function trampoline process
Function trampoline process

How code is interpreted

Live Edit compiles code on the fly. The resulting .class files are pushed, trampolined (as previously described), and then interpreted on the device. This interpretation is performed by the LiveEditInterpreter. The interpreter is not a full VM inside ART. It is a Frame interpreter built on top of ASM Frame. ASM Frame handles the low level logistics such as the stack/local variables's push/load, but it needs an Interpreter to actually execute opcode. This is what the OpcodeInterpreter is for.

Flow chart of Live Edit interpretation
Live Edit interpretation flow

Live Edit Interpreter is a simple loop which drives ASM/Interpreter opcodes interpretation.

Some JVM instructions cannot be implemented using a pure Java interpreter (in particular invokeSpecial and monitorEnter/Exit are problematic). For these, Live Edit uses JNI.

Dealing with lambdas

Lambdas are handled in a different manner because changes to lambda captures can result in changes in VM classes that are different in many method signatures. Instead, new lambda-related updates are sent to the running device and loaded as new classes instead of redefining any existing loaded classes as described in the previous section.

How does recomposition work?

Developers wanted a seamless and frictionless new approach to program Android applications. A key part of the Live Edit experience is the ability to see the application updated while the developer continuously writes code, without having to explicitly trigger a re-run with a button press. We needed a UI framework that has the ability to listen to model changes within the application and perform optimal redraws accordingly. Luckily, Jetpack Compose fits this task perfectly. With Live Edit, we added an extra dimension to the reactive programming paradigm where the framework also observes changes to the functions’ code.

To facilitate code modification monitoring, the Jetpack Compose compiler supplies Android Studio with a mapping of function elements to a set of recomposition group keys. The attached JVMTI agent invalidates the Compose state of a changed function in an asynchronous manner and the Compose runtime performs recomposition on Composables that are invalidated.

How we handle runtime errors during recomposition

Moving image of Live edit handling a runtime error
Live Edit handling a runtime error

While the concept of a continuously updating application is rather exhilarating, our field studies showed that sometimes when developers are writing code, the program can be in an incomplete state where updating and re-executing certain functions would lead to undesirable results. Besides the automatic mode where updates are happening almost continuously, we have introduced two manual modes for the developer who wants a bit more control on when the application gets updated after new code is detected.

Even with that in mind, we want to make sure common issues caused by executing incomplete functions do not cause the application to terminate prematurely. Cases where a loop’s exit condition is still being written are detected by Live Edit to avoid an infinite loop within the program. Also, if a Live Edit update triggers recomposition and causes a runtime exception to be thrown, the Compose runtime will catch such an exception and recompose using the last known good state.

Consider the following piece of code:

var x = y / 10

Suppose the developer would like to change 10 to 50 by deleting the character 1 and inserting character 5 after. Android Studio could potentially update the application before the 5 is inserted and thus create a division-by-zero ArithmeticException. However, with the added error handling mentioned, the application would simply revert to “y / 10” until further updates are done in the editor.

What’s coming?

The Android Studio team believes Live Edit will change how UI code is written in a positive way and we are committed to continuously improve the Live Edit development experience. We are working on expanding the types of edits developers can perform. Furthermore, future versions of Live Edit will eliminate the need to invalidate the whole application during certain scenarios.

Additionally, PSI event detection comes with limitations such as when the user edits import statements. To solve this problem, future versions of Live Edit will rely on .class diffing to detect changes. Lastly, the full persisting functionality isn't currently available. Future versions of Live Edit will allow the application to be restarted outside of Android Studio and retain the Live Edit changes.

Get started with Live Edit

Live Edit is ready to be used in production and we hope it can greatly improve your experience developing for Android, especially for UI-heavy iterations. We would love to hear more about your interesting use cases, best practices and bug reports and suggestions.

Java is a trademark or registered trademark of Oracle and/or its affiliates.

Android Studio Giraffe is stable

Posted by Mayank Jain, Product Manager

Today, we are thrilled to announce the stable release of Android Studio Giraffe 🦒 : The official IDE for building Android apps!

In this Android Studio release, we have upgraded the IntelliJ platform to 2022.3, including a brand new visual look and feel in Android Studio, improvements to Live Edit, Compose animation previews, a new Device Explorer, a new SDK upgrade assistant, ability to use Kotlin DSL in your Gradle build scripts and much more. Read on to learn more about how Android Studio Giraffe 🦒 can help supercharge your developer productivity.

Thank you to all of you who have given us feedback and used Android Studio since we launched our initial version just over 10 years ago. Download the latest stable version today and we look forward to continuing to deliver on our commitment of delivering a best-in-class integrated development environment (IDE) focused on Android app development!

IDE Enhancements

New UI for Android Studio (Preview) 
Along with the much anticipated IntelliJ Platform update, we are excited to share a preview of the visual look that we call the “New UI” for Android Studio Giraffe. The redesigned theme aims to reduce visual complexity, provide easier access to essential features, and disclose complex functionality as needed—resulting in a modern, cleaner look and feel.

The New UI was first released as an early preview in IntelliJ 2022.2 to gather feedback from users and other IntelliJ-based IDEs to ensure it could fully replace the previous UI. Since then, it’s progressed to beta in IntelliJ 2022.3, with many bug fixes and improvements.

With the Giraffe release, we’ve started adopting the new UI, with several Android Studio specific changes, such as optimizing the default main toolbar and tool windows configurations for Android and refreshing our iconography in the style. We are excited by this new design direction and will continue adoption through the Hedgehog release and onward.

To use the New UI, enable it in Settings > Appearance & Behavior > New UI. For a full list of changes, see the IntelliJ New UI documentation.

Image showing the new UI adopted from IntelliJ
The New UI adopted from IntelliJ
New diagnostic & bug reporting tool 
As you try the New UI, please provide us detailed feedback through our new diagnostic & bug reporting tool that makes it easier to report bugs with relevant log files already attached. The new bug reporting tool is found at Help > Collect Logs and Diagnostic Data.

Image showing the new diagnostic & bug reporting tool
New diagnostic & bug reporting tool
Updated Device Explorer 
Also shipping with the new UI, is an updated Device Explorer (known as the Device File Explorer in previous versions of Android Studio). In the Device Explorer, files and related actions are located in the Files tab. Additionally, in the new Processes tab, you can view a list of debuggable processes for the connected device. From there you can also select a process and perform a kill , force-stop, or attach the debugger to a given process.

Image showing a screen capture of the updated device explorer
Updated Device Explorer

Coding Productivity

Use Live Edit to update composables in real time 
Live Edit lets you update composables in Android emulators and physical devices in near real time. You can now edit composables and see the UI changes on the running device without re-deploying your app.

This helps you by minimizing the context switching between writing and building your app, letting you focus on writing code longer without interruption. To try Live Edit, enable it via Settings > Editor > Live Edit and use Android Gradle Plugin (AGP) 8.1 or higher and Jetpack Compose Runtime 1.3.0 or higher.

Moving image illustrating updating composables in real time in Live Edit
Use Live Edit to update composables in real time
 
Compose Animation Preview - Extend animation support  Compose Animation Preview now supports a number of additional Compose APIs, such as animate*AsState, CrossFade, rememberInfiniteTransition, and AnimatedContent (in addition to updateTransition and AnimatedVisibility). Additionally, now there are new pickers that let you set non-enum or boolean states to debug your Compose animation using precise inputs. For all supported Compose Animation APIs, you can play, pause, scrub & control speed.

Moving image illustrating extended animation support in Compose Animation Preview
Compose Animation Preview - Extend animation support
 
Android SDK Upgrade Assistant 
The new Android SDK upgrade assistant lets you see the steps required to upgrade the targetSdkVersion, or the API level that your app targets, directly in the IDE. It also pulls upgrade-related documentation directly from the Android Developer site into its tool window, so you don't have to jump back and forth between your browser and the IDE. For each migration step, it highlights the major breaking changes and how to address them, and even filters the full list of changes to only show steps relevant to your app.

To open the Android SDK Upgrade Assistant, go to Tools > Android SDK Upgrade Assistant.

Image of Android SDK Upgrade Assistant
Android SDK Upgrade Assistant

Improvements to the build system

Kotlin DSL in your Gradle build scripts 
Kotlin is not only more readable, it also offers better compile-time checking and IDE support. With Android Studio Giraffe, we are excited to offer the official support for Kotlin DSL in your Gradle build scripts. This means that Kotlin is the default language used in your project code, including UI with Jetpack Compose, and now editing the build scripts too!

Now, when you are creating new projects or modules starting from Android Studio Giraffe, you get the Kotlin DSL by default. And if you want to migrate existing builds, check out the Kotlin DSL migration guide.

We've been working with the Gradle and JetBrains teams on this improvement, and you can read more in their related announcements: Gradle Blog; JetBrains Blog.

Additionally, we’ve also added experimental support for TOML-based Gradle Version Catalogs, a feature that lets you manage dependencies in one central location and share dependencies across modules or projects. Android Studio now makes it easier to configure version catalogs through editor suggestions and integrations with the Project Structure dialog, plus the New Project Wizard.

Image of Android SDK Upgrade Assistant
Kotlin DSL in your Gradle build scripts

Download info during Gradle sync
 
If you’ve ever wondered if any unexpected dependency downloads are negatively impacting your sync performance, the new Sync tool window now includes a summary of time spent downloading dependencies, and a detailed view of downloads per repository. This view updates live as sync takes place. It can even help you identify inefficiencies in how you configure your repositories.

Moving image showing download info during gradle sync
Download info during Gradle sync

Automatic per-app language support 
Typically, multilingual users set their system language to one language—such as English—but they want to select other languages for specific apps, such as Dutch, Chinese, or Hindi. Android 13 introduced support for per-app language preferences, and now Android Gradle plugin 8.1 and higher can configure your app to support it automatically based on your project’s resources. Learn more.

Make selected modules toolbar button 
With Android Studio Giraffe, you can now build only the current module you're working on by selecting the Make Selected Modules build option in the toolbar. This new option lets you check that the code you just wrote compiles without building more than needed. Learn more.

Image of Android SDK Upgrade Assistant
Kotlin DSL in your Gradle build scripts

Summary

To recap, Android Studio Giraffe includes these new enhancements and features. You can always learn more with our detailed release notes.

IDE Enhancements
  • Upgraded to IntelliJ Platform 2022.3 : Includes a number of features and bug fixes
  • New UI for Android Studio : Android Studio now adopts a number of improvements from the IntelliJ's modern design language
  • Updated Device Explorer : Offers two new tabs : Files & Processes from where you can view a list of debuggable processes, perform a kill, force-stop, or attach the debugger
  • New diagnostic & bug reporting tool : Easier to report bugs for Android Studio with relevant log files already attached
Coding Productivity
  • Use Live Edit to update composables in real time : Update composables in real time, edit composables and see the UI changes on the running device without re-deploying your app
  • Compose Animation Preview - Extend animation support : Now supports a number of additional Compose APIs and new pickers that let you set non-enum or boolean states to debug your Compose animation using precise inputs
  • Android SDK Upgrade Assistant : Now lets you see the steps required to upgrade the targetSdkVersion, or the API level that your app targets directly in Studio
Improvements to the build system
  • Kotlin DSL in your Gradle build scripts : With official support for Kotlin DSL in your Gradle build scripts, Kotlin is now the single default language for project code, UI with Jetpack Compose, and now for build scripts
  • Download info during Gradle sync : Shows a summary of time spent downloading dependencies and a detailed view of downloads per repository
  • Automatic per-app language support : AGP can now automatically configure per-app language preferences
  • Make selected modules toolbar button : build only the current module you're working on by selecting the Make Selected Modules build option in the toolbar

Download Android Studio Today!

Now is the time to download Android Studio Giraffe 🦒 to incorporate the new features into your workflow. As always, we appreciate any feedback on things you like and issues or features you would like to see. If you find a bug or issue, please file an issue and also check out known issues. Remember to also follow us on Twitter, Medium, or YouTube for more Android development updates!