Android studio - 部署发布 apk 而不是调试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23979540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:40:58  来源:igfitidea点击:

Android studio - deploy the release apk instead of debug

androidandroid-studio

提问by joe_deniable

The run configurations in Android Studio only let you deploy the default (debugging) APK, but I have built a release APK by running gradle assembleDebug from within Android Studio (as an external tool) and would like to deploy that instead. But it doesn't seem like you can change the APK which Android Studio installs. There is an option to deploy a custom artifact, but I'm not sure what that is, or if it would help, and anyway, there doesn't seem to be an option to create a new artifact in the Android Studio Project Structure dialog.

Android Studio 中的运行配置仅允许您部署默认(调试)APK,但我通过从 Android Studio(作为外部工具)运行 gradle assembleDebug 构建了一个发布 APK,并希望改为部署它。但您似乎无法更改 Android Studio 安装的 APK。有一个选项可以部署自定义工件,但我不确定那是什么,或者它是否有帮助,无论如何,似乎没有在 Android Studio 项目结构对话框中创建新工件的选项.

Does anyone know how I can specify the path of the APK which Android Studio deploys? I know I can install from the command line with adb, but it would speed things up if I could just click a button. Thanks.

有谁知道我如何指定 Android Studio 部署的 APK 的路径?我知道我可以从命令行使用 adb 进行安装,但如果我只需单击一个按钮,它就会加快速度。谢谢。

回答by nenick

On the left should be a "Build Variants" tab. There you can switch between your build types. If there no tabs visible than look left buttom for a monitor symbol and click it. Then you should find the build types. The selected one will be installed.

左侧应该是“构建变体”选项卡。在那里您可以在构建类型之间切换。如果没有可见的选项卡,请查看左下角的监视器符号并单击它。然后你应该找到构建类型。将安装选定的一个。

回答by Automatico

Click the Build Variationtab on the far left side. If it is not there, press the monitor icon in the far left corner (the darker gray area):

单击Build Variation最左侧的选项卡。如果不存在,请按最左角(较深的灰色区域)的监视器图标:

Monitor Icon

监视器图标

In the build variation tab change from debugto releaseby clicking the list item.

在构建变体选项卡debugrelease,单击列表项从 更改为。

Build Variation

构建变化

回答by yoAlex5

Run a command

运行命令

./gradlew assemble<variant_name>
//for example
./gradlew assembleRelease

After success build you can find .apkfile at

成功构建后,您可以在以下位置找到.apk文件

project_path/app/build/outputs/apk/<variant_name>/
//for example
project_path/app/build/outputs/apk/release/

or just install via adb

或者直接通过 adb 安装

adb install apk_path

Read more here

在这里阅读更多