分享好友 最新动态首页 最新动态分类 切换频道
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.

最新文章
置顶微信小程序开发快速入门-第一个页面编写(2/5)精选热门
我相信很多小伙伴看完上次的《微信小程序开发快速入门-小程序之开发前准备(1/5)》已经迫不及待想要开始编码了,今天就满足大家把代码给大家安排上!今天主要分享的内容有以下 2 个点:在这里我们会从官方提供的案例去阅读代码中的秘密,
门头沟将与百度、华为合作,共推京西人工智能产业发展
12月28日,门头沟区人民政府与百度智能云联合主办的“2023北京大模型产业暨数字经济发展论坛”成功举办。百度、华为、百图生科、瑞莱智慧等企业代表共话大模型与千行百业的深度融合。论坛上,门头沟区人民政府与百度智能云签署战略合作协议
网址批量缩短:方便快捷的链接管理工具
在如今信息爆炸的时代,网址的使用频率也随之增加。无论是在社交媒体平台分享链接,还是在电子邮件、信息传递等场景中使用,长串复杂的网址无疑会降低用户体验。为了解决这个问题,网址批量缩短工具应运而生。这些工具不仅可以简化网址,还
阿里智能设计实验室负责人乐乘:当设计遇上AI
在今年UCAN大会开场,阿里巴巴集团UED委员会委员长杨光发布的智能设计平台——鲁班,便出自乐乘的团队。此平台是通过人工智能算法和大量数据训练机器学习设计。通过一段时间的学习,此平台从去年“双十一”前就已经在阿里内部大规模投入使
高清美女写真生成攻略:用搜狐简单AI开启你的AI画女友之路!
访问工具: 打开微信,搜索小程序“搜狐简单AI”,点击进入。选择模板: 在首页选择“美女写真”模板,该页面会展示多个风格的选项供你选择。自定义设置: 选择你喜爱的风格后,你可以自定义角色的衣着、发型、面部特征等,尽量贴合你心目中的
达州通川区考研政治集训培训机构咨询热线:   在线咨询: 点击交谈
新闻标题:达州通川区学考研政治集训学校排名近期更新达州通川区考研政治集训培训机构是致力于为大学生群体提供学业与职业发展的翘楚机构。自2007年启动运营至今,凭借先进教育技术和优异培训效果,在研究生入学考试、大学生就业创业等教育
磁力全聚合
《磁力全聚合》是款功能强大的影视播放神器,这里汇集各种海内外影视资源,让你在这里体验到一站式的看片体验。软件界面简约清爽无广告,使用流程简单易上手,在这里力致给你全新的视觉盛宴。你还等什么?赶快下载体验吧。磁力全聚合是一款
Uptime Kuma:一款简单易用的监控工具
主要特点总览: - 支持超过十种监控方式,包括HTTP/HTTPS、TCP、Ping等,还包括Docker和中间件监控。 - 提供动态且响应迅速的用户界面,使用户能轻松管理监控任务。 - 集成了90多种通知服务,如Telegram、Di
据说媲美Portainer,一款国人开发的Docker可视化管理面板『DPanel』
哈喽小伙伴们好,我是Stark-C~根据作者自己的描述,它的主要功能为:全中文的界面,相比于 portainer 更友好完善的容器管理功能,提供域名转发,文件管理,日志监控等功能。轻松对容器内的文件进行管理。提供容器之间的关联功能,便于多个
深度解析,小红书权重提升秘诀,如何高效提高权重指数
1、坚持原创:原创内容是提升笔记权重的核心要素,平台会根据笔记的文字和图片原创度,给予相应的权重分数,原创度越高,权重分越高,从而提升笔记的曝光率和流量,若100字内的原创度低于60%,则几乎不会有权重,导致笔记受限流。2、删除笔
相关文章
推荐文章
发表评论
0评