在风味和构建类型之外覆盖应用程序ID [英] Overwrite Application Id Outside of Flavors and Build Types

查看:56
本文介绍了在风味和构建类型之外覆盖应用程序ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有多种风格(A,B,C)和两种构建类型(debugrelease)的应用程序

I have an application with many flavors (A,B,C) and two build types (debug,release)

在构建类型debug中,我向应用程序ID添加一个后缀,如下所示:

In the build type debug I add a suffix to the application ID like so:

debug {
    applicationIdSuffix '.debug'
}

这对于风味AB很好,但是我不能在风味C的应用程序ID后面附加.debug.

This is fine for flavors A and B but I can't append .debug to flavor C's application ID.

我已经研究了对变体的覆盖,就像对versionCode一样,但是没有运气.

I have looked at overriding on the variant like I have for the versionCode but no luck.

    applicationVariants.all { variant ->
        def changedVersionCode = variant.versionCode
        variant.
        variant.outputs.each { output ->
            if (variant.buildType.name != "debug") {
                output.setVersionCodeOverride(project.ext.versionCode)
                changedVersionCode = project.ext.versionCode
            } 
        }
        changeApkFileName(variant,changedVersionCode)
    }

是否可以根据口味覆盖变体应用程序ID.例如,我的计划是执行以下操作:

Is it possible to override a variants application ID depending on the flavor. For example my plan was to do something like this:

variant.buildType.name.replace('.debug','')

推荐答案

是否可以根据口味覆盖变体应用程序ID

Is it possible to override a variants application ID depending on the flavor

是的.

您无法看到预期ID的原因是:

The reason you are not able to see the expected id is:

由于Gradle在产品风味之后应用了构建类型配置,因此"C"构建变体的应用程序ID将为"<your-applicaion-id>.debug".

因此,如果您希望它的不同口味有所不同,则必须将applicationIdSuffix分开以用于不同的调味剂,并按如下所示将其从debug {}中移除:

So if you want it to be different for different flavors then you have to segregate the applicationIdSuffix for different flaovors and remove it from debug {} as follows:

android {
    defaultConfig {
        applicationId "<your-application-id>"
    }
    productFlavors {
        A {
            applicationIdSuffix ".debug"
        }
        B {
            applicationIdSuffix ".debug"
        }
        C {
            applicationIdSuffix ""
        }
    }
}

有关更多详细信息,请参阅正式的文档.

For more details, refer to official documentation.

这篇关于在风味和构建类型之外覆盖应用程序ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆