You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否通过快捷方式切换指定构建变体的Instant Run状态?

Can I toggle Instant Run's enabled state via a shortcut for a specific build variant?

Absolutely, you can set up shortcuts to toggle Instant Run's state—either globally or tailored to your specific build variant! Here's how to make it work in Android Studio:

1. Global Instant Run Toggle Shortcut

Android Studio has a built-in action for this, it just doesn’t come with a default shortcut. Here’s how to assign one:

  • Open Settings (Windows/Linux: File > Settings; Mac: Android Studio > Settings)
  • Navigate to the Keymap section
  • Search for Toggle Instant Run in the search bar
  • Right-click the action, select Add Keyboard Shortcut, and set a combination that works for you (e.g., Ctrl+Shift+I on Windows, Cmd+Shift+I on Mac)
  • Hit Apply and OK to save the setting

Now you can use that shortcut to instantly flip Instant Run on or off across all variants.

2. Variant-Specific Toggle (Combine with Build Variant Switch)

If you want Instant Run to behave differently for your specific variant, pair a build variant shortcut with Gradle configuration:

Step 1: Configure Instant Run per variant in Gradle

Open your app module's build.gradle file and set the instantRun.enabled flag for your target variant:

android {
    buildTypes {
        yourCustomVariant { // Replace with your specific build variant name
            instantRun.enabled = true // Set to false to disable for this variant
        }
        // You can set other variants as needed
        debug {
            instantRun.enabled = false
        }
    }
}

Sync your Gradle project after making changes.

Step 2: Assign a shortcut to switch build variants

  • Go back to the Keymap settings
  • Search for Switch Build Variant
  • Assign a shortcut to this action (e.g., Ctrl+Shift+V)

Now you can quickly switch to your custom variant (where Instant Run is enabled) or another variant (where it’s disabled) with the shortcut.

3. Advanced: Custom Macro for One-Click Toggle

For a truly seamless workflow, create a macro that combines switching to your specific variant and toggling Instant Run:

  • Go to Edit > Macros > Start Macro Recording
  • Perform the actions: switch to your custom build variant, then trigger the Toggle Instant Run action
  • Stop recording, name your macro (e.g., "Toggle Instant Run for Custom Variant")
  • Head to Keymap, find your new macro, and assign a shortcut to it

This lets you handle both the variant switch and Instant Run toggle in a single keystroke.

Hope this helps you speed up your development process! 🚀

内容的提问来源于stack exchange,提问作者Jim Clermonts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:49:18