分享好友 最新动态首页 最新动态分类 切换频道
Build and run your app
2024-12-26 20:11

To see how your app looks and behaves on a device, you need to build and run it. Android Studio sets up new projects so that you can deploy your app to a virtual or a physical device with just a few clicks.

This overview focuses on how to use Android Studio to build and run your app for testing and debugging. For information on how to use Android Studio to build your app so that it can be released to users, see Build your app for release to users. For more detailed information about managing and customizing your build with or without Android Studio, see Configure your build.

To build and run your app, follow these steps:

  1. In the toolbar, select your app from the run configurations menu.
  2. In the target device menu, select the device that you want to run your app on.

    If you don't have any devices configured, you need to either create an Android Virtual Device to use the Android Emulator or connect a physical device.

Android Studio warns you if you attempt to launch your project to a device that has an error or a warning associated with it. Iconography and stylistic changes differentiate between errors (device selections that result in a broken configuration) and warnings (device selections that might result in unexpected behavior but are still runnable).

If an error occurs during the build process, Gradle may recommend command-line options to help you resolve the issue, such as or . To use command-line options with your build process:

  1. Open the Settings or Preferences dialog:
    • On Windows or Linux, select File > Settings from the menu bar.
    • On macOS, select Android Studio > Preferences from the menu bar.
  2. Navigate to Build, Execution, Deployment > Compiler.
  3. In the text field next to Command-line Options, enter your command-line options.
  4. Click OK to save and exit.

Gradle applies these command-line options the next time you try building your app.

The default way to build and run your app in Android Studio should be sufficient to test a simple app. However, you can use these build and run features for more advanced use cases:

  • If you have an app with multiple build variants or versions, you can choose which build variant to deploy by using the Build Variants tool window. For more information about running a specific build variant, see the Change the build variant section.

  • To fine-tune app installation, launch, and test options, you can change the run/debug configuration. For more information about creating custom run/debug configurations, see the Create run/debug configurations section.

  • We recommend that you use Android Studio for your development needs, but you can also deploy your app to a virtual or physical device from the command line. For more information, see Build your app from the command line.

In Android Studio 3.5 and higher, 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. This flexibility helps you control how much of your app is restarted when you want to deploy and test small, incremental changes while preserving your device's current state.

Apply Changes uses that are supported on devices running Android 8.0 (API level 26) or higher. To learn more about how Apply Changes works, see .

Requirements

Apply Changes actions are only available when you meet the following conditions:

  • You build the APK of your app using a debug build variant.
  • You deploy your app to a target device or emulator that runs Android 8.0 (API level 26) or higher.

Use Apply Changes

Use the following options when you want to deploy your changes to a compatible device:

You can also perform this action by pressing Control+Alt+F10 (Control+Command+Shift+R on macOS).

You can also perform this action by pressing Control+F10 (Control+Command+R on macOS).

Enable run fallback for Apply Changes

If you don't want to be prompted every time this occurs, you can configure Android Studio to automatically rerun your app when changes can't be applied. To enable this behavior, follow these steps:

  1. Open the Settings or Preferences dialog:

    • On Windows or Linux, select File > Settings from the menu.
    • On macOS, select Android Studio > Preferences from the menu.
  2. Navigate to Build, Execution, Deployment > Deployment.

  3. Select the checkboxes to enable automatic run fallback for either or both of the Apply Changes actions.

  4. Click OK.

Platform-dependent changes

Some features of Apply Changes depend on specific versions of the Android platform. To apply these kinds of changes, your app must be deployed to a device running that version of Android (or higher). For example, adding a method requires Android 11 or higher.

Limitations of Apply Changes

Apply Changes is designed to speed up the app deployment process. However, there are some limitations on when it can be used.

Code changes that require app restart

Some code and resource changes can't be applied until the app is restarted, including the following:

  • Adding or removing a field
  • Removing a method
  • Changing method signatures
  • Changing modifiers of methods or classes
  • Changing class inheritance
  • Changing values in enums
  • Adding or removing a resource
  • Changing the app manifest
  • Changing native libraries (SO files)
Libraries and plugins
Code that directly references content in an installed APK

If you encounter any other issues while using Apply Changes, file a bug.

Live Edit is an experimental feature in the Android Studio that lets you update composables in emulators and physical devices in real time. This functionality minimizes context switches between writing and building your app, letting you focus on writing code longer without interruption.

To change the build variant Android Studio uses, do one of the following:

  • Select Build > Select Build Variant in the menu.
  • Select View > Tool Windows > Build Variants in the menu.
  • Click the Build Variants tab on the tool window bar.

For projects without native/C++ code, the Build Variants panel has two columns: Module and Active Build Variant. The Active Build Variant value for the module determines which build variant the IDE deploys to your connected device and is visible in the editor.

To switch between variants, click the Active Build Variant cell for a module and choose the desired variant from the list.

For projects with native/C++ code, the Build Variants panel has three columns:

  • Module
  • Active Build Variant
  • Active ABI

The Active Build Variant value for the module determines the build variant that the IDE deploys to your device and is visible in the editor. For native modules, the Active ABI value determines the ABI that the editor uses, but doesn't impact what is deployed.

To change the build variant or ABI, click the cell for the Active Build Variant or Active ABI column and choose the desired variant or ABI from the list. After you change the selection, the IDE syncs your project automatically. Changing either column for an app or library module applies the change to all dependent rows.

By default, new projects are set up with two build variants: a debug variant and release variant. You need to build the release variant to prepare your app for public release. To define other variations of your app with different features or device requirements, you can define additional build variants.

Conflicts in Android Studio Build Variants dialog

In the Android Studio Build Variants dialog, you might see error messages indicating conflicts between build variants, such as the following:

This error doesn't indicate a build issue with Gradle. It indicates that the Android Studio IDE can't resolve symbols between the variants of the selected modules.

For example, if you have a module that depends on variant of module , but has variant selected in the IDE, you have unresolved symbols in the IDE. Suppose depends on a class that is only available in ; when is selected, that class is not known by the IDE. Therefore it fails to resolve the class name and shows errors in the module's code.

These error messages appear because the IDE can't load code for multiple variants simultaneously. In terms of your app’s build, however, the variant selected in this dialog has no effect, because Gradle builds your app with the source code specified in your Gradle build recipes, not based on what’s currently loaded in the IDE.

When you run your app for the first time, Android Studio uses a default run configuration. The run configuration specifies whether to deploy your app from an APK or an Android App Bundle as well as the module to run, package to deploy, activity to start, target device, emulator settings, Logcat options, and more.

The default run/debug configuration builds an APK, launches the default project activity, and uses the Select Deployment Target dialog for target device selection. If the default settings don't suit your project or module, you can customize the run/debug configuration or create a new one at the project, default, and module levels.

最新文章
淘宝人群推广和货品运营区别是什么?作者:小果 时间:2024-12-16 阅读:4533
淘宝运营策略:人群推广与货品运营的深度解析在淘宝这个竞争激烈的电商平台上,运营策略的选择至关重要。其中,人群推广和货品运营是两种常见的运营方式,它们各自具有独特的优势和适用场景。下面,我们将对这两种运营方式进行详细解析,并
磁力在线搜索引擎蜘蛛
搜索引擎是我日常工作中用得最多的一款工具,国内常用的搜索引擎包括Baidu,sougou,bing等。但我本篇要纪录的并不是这些常用的搜索引擎,而是信息安全从业人员必备的几款网络搜索引擎。本篇要介绍的搜索引擎包括:Shodan,censys,钟馗之
纯干货开发一个小程序需要多少钱?不同公司的报价差别太大,看完就懂了
各位迈友大家好~小迈迈又来跟大家叨叨了。一直以来,迈象网都十分重视用户的反馈,最近我们也根据用户的呼声来说说,开发一个小程序需要多少钱。纯干货和网上搜索的都不一样 ,看完这个要是不明白 ,你找我免费给你做个小程序。1.小程序三
百度地域性多个关键词排名的小技巧
重点导读:做SEO还是有比较大的操作空间的,不是SEO流量不好做,而是我们没有打开获取更多流量的方式。在优化地域性的朋友,可以试试本文说到的这个简单技巧。 百度地域性是很重要的,如果我们能够在做SEO的时候做好规划,就能获得大量精准
私域营销:解锁品牌增长新引擎
  在数字化营销日新月异的今天,私域营销作为品牌与消费者深度连接的重要策略,正逐渐成为市场营销领域的一大热点。私域营销,简而言之,就是通过建立和管理品牌自有的、直接面向消费者的沟通渠道,实现用户数据的积累、分析与应用,从而
免费漫画阅站app1.1.99版下载
字如其名,漫画免费看。《免费漫画阅站 1.1.99版》是一款非常可以尽情畅看漫画的神器,在免费漫画阅站软件内。海量的漫画资源,各种类型的漫画,绝对能够满足你的漫画阅读需求。在免费漫画阅站软件内,高清的漫画资源,更有个性化的推送功
速腾 carplay 点击无反应是怎么回事
仪表盘一直亮不灭可能有多种原因。一是牵引力控制系统TCS出现故障。二是车辆引擎灯、电池灯常亮这可能表示车辆电子系统有问题或者发动机异常需检查故障代码并维修。三是机油灯、刹车灯、轮胎压力灯等提醒灯常亮要及时处理。
网站点击排名优化,提升网站流量与用户体验的全方位策略,网站点击排名优化什么意思
网站点击排名优化是指通过一系列技术和策略,提高网站在搜索引擎中的排名,从而增加网站流量和用户体验。这包括优化网站内容、结构、链接等方面,以提高网站在搜索引擎中的可见性和权威性。通过点击排名优化,网站可以吸引更多的访问者,提
搜狗浏览器下载2015官方版 v6.2 最新电脑版
是一款拥有极速浏览速度的双核浏览器。搜狗浏览器下载2015采用最新的chrome内核和ie内核,其浏览速度毋庸置疑,但是现在市场上的浏览器也同样采用这两个内核,于是搜狗推出了智能预读系统,用户在输入网址时,浏览器智能识别用户输入的地址
第三季全球手机排行榜 诺基亚独占七席
  11月4日消息,据国外媒体报道,知名电子产品批发商RCS日前表示,在今年第三季度的全球十大畅销手机排行榜上,诺基亚依然实力强劲,独占了7个席位。而在上一季度排名第五的大众宠儿iPhone 在本季度却榜上无名。  以下是RCS统计的第三
相关文章
推荐文章
发表评论
0评