简体   繁体   English

Android Studio 默认在 build.gradle 中构建什么 Product Flavor?

[英]What Product Flavor does Android Studio build by default in build.gradle?

We have an Android project that uses the new Gradle build system, and we use Android Studio as a development tool.我们有一个使用新 Gradle 构建系统的 Android 项目,我们使用 Android Studio 作为开发工具。 When there are several product flavors specified in build.gradle , we notice that Android Studio builds the first one specified alphabetically.build.gradle指定了多种产品风味时,我们注意到 Android Studio 会按字母顺序构建第一个指定的产品风味。 Is there a way to tell Android Studio to build and test only a specific product flavor during development?有没有办法告诉 Android Studio 在开发过程中只构建和测试特定的产品风格?

On the lower left of the Studio window there's a docked view called "Build Variants".在 Studio 窗口的左下方有一个名为“Build Variants”的停靠视图。

Open it and choose whichever variant you want to work on.打开它并选择您想要处理的任何变体。 This will impact which variant is built but also the enabled source folders, which will drive completion in code and resources editors.这将影响构建的变体以及启用的源文件夹,这将推动代码和资源编辑器中的完成。

Currently there appears to be no way to select default flavor.目前似乎无法选择默认风格。 There is a feature request in Android Issue Tracker for it: Android 问题跟踪器中有一个功能请求:

https://code.google.com/p/android/issues/detail?id=64917 https://code.google.com/p/android/issues/detail?id=64917

You can star/vote the request, so it gets higher priority on Android development tools backlog.您可以为请求加星标/投票,因此它在 Android 开发工具积压工作中获得更高的优先级。

Yes, there is a way:是的,有一种方法:

android {
    productFlavors {
        foo {
            isDefault true
        }
    }
}

And otherwise variants with the debug build type are favoured.并且具有调试构建类型的其他变体受到青睐。

It was added in Android Studio 3.5, see feature request :它是在 Android Studio 3.5 中添加的,请参阅功能请求

"Included in Android Gradle Plugin 3.5.0-alpha08 and Android Studio 3.5 Canary 8 [3.5.0.7]. “包含在 Android Gradle 插件 3.5.0-alpha08 和 Android Studio 3.5 Canary 8 [3.5.0.7] 中。

The heuristic for projects using older AGP and projects without explicit settings has also been updated to favour variants with the build type debug, as described in the commit message."使用旧 AGP 的项目和没有显式设置的项目的启发式也已更新,以支持具有构建类型调试的变体,如提交消息中所述。”

What actually worked for me is enabling "Android Studio Preferences -> Experimental -> Only sync the active variant".实际上对我有用的是启用“Android Studio Preferences -> Experimental -> Only sync the active variant”。 After you select the desired build variant once, AS will keep the selected build variant when reopening or when re-syncing the project, basically solving the original problem.选择一次想要的构建变体后,AS在重新打开或重新同步项目时会保留选择的构建变体,基本解决了原来的问题。

AS/AGP v4.1. AS/AGP v4.1。

On latest of android studio, on menu bar, go to Build > Select build Variant , if it's greyed out (disabled), open the project directory and then open the app section then go to that button again.在最新的 android studio 上,在菜单栏上,转到Build > Select build Variant ,如果它变灰(禁用),请打开项目目录,然后打开app部分,然后再次转到该按钮。 After you've clicked on it, it will open up a window on the sidebar called Build Variants , from there you can select which build variant you want to build, then click on debug and it will build the variant you selected.单击它后,它会在侧边栏上打开一个名为Build Variants的窗口,您可以从那里选择要构建的构建变体,然后单击调试,它将构建您选择的变体。

You can specify the command run In Section Before launch Gradle-aware Make您可以在启动 Gradle-aware Make 之前指定在部分中运行的命令

You can list all gradle tasks by gradlew tasks您可以通过gradlew tasks列出所有 gradle gradlew tasks

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM