gpt4 book ai didi

android gradle - 如何创建新的产品风格但重用另一种风格的值?

转载 作者:太空狗 更新时间:2023-10-29 14:42:22 35 4
gpt4 key购买 nike

我想在我的 build.gradle 文件中制作一个新的风格,但它是另一种风格的完整副本。我将其用于测试目的。只有 applicationid 后缀会有所不同。我想将这种口味称为 beta。但我希望有一种方法不必重复代码。因为它具有与我的暂存风格相同的设置,所以有没有一种方法可以让 gradle 复制与暂存风格相同的设置。我的口味定义如下:

    productFlavors {

def STRING = "String"
def BOOLEAN = "boolean"
def TRUE = "true"
def FALSE = "false"
def FLAVOR = "FLAVOR"
def RETROFIT_LOG_ALL = "RETROFIT_LOG_ALL"
def BASE_ENDPOINT = "BASE_ENDPOINT"


staging {
buildConfigField STRING, BASE_ENDPOINT, '"https://pepsi-staging-api.pmlo.co"'
buildConfigField STRING, BASE_IMGIX_ENDPOINT, '"myappfashion.imgix.net"'
buildConfigField STRING, BASE_ENDPOINT_WEB, '"www.pepsi-staging.pmlo.co"'
buildConfigField BOOLEAN, RETROFIT_LOG_ALL, TRUE
manifestPlaceholders = [appDrawerName: "myapp-Staging"]
ext.enableCrashlytics = false
versionNameSuffix '-STAGING'
applicationIdSuffix 'staging'
}


//why do i have to copy the same settings again, is there a way to just over ride from the staging flavor the things i want changed ?
beta {
buildConfigField STRING, BASE_ENDPOINT, '"https://pepsi-staging-api.pmlo.co"'
buildConfigField STRING, BASE_IMGIX_ENDPOINT, '"myappfashion.imgix.net"'
buildConfigField STRING, BASE_ENDPOINT_WEB, '"www.pepsi-staging.pmlo.co"'
buildConfigField BOOLEAN, RETROFIT_LOG_ALL, TRUE
manifestPlaceholders = [appDrawerName: "myapp-Staging"]
ext.enableCrashlytics = false
versionNameSuffix '-beta' //only these two thigns are different
applicationIdSuffix 'beta'
}


prod {
// applicationId "com.mobile.myapp"
buildConfigField STRING, BASE_ENDPOINT, '"https://api.myappfashion.com"'
buildConfigField STRING, BASE_IMGIX_ENDPOINT, '"myappfashion.imgix.net"'
buildConfigField STRING, BASE_ENDPOINT_WEB, '"www.myappfashion.com"'
buildConfigField BOOLEAN, RETROFIT_LOG_ALL, FALSE
ext.enableCrashlytics = true
manifestPlaceholders = [appDrawerName: "myapp"]
}

}

i just want to override versionNameSuffix & applicationIdSuffix only in beta and copy all values from staging. is there a way not to duplicate code like this example ?

最佳答案

在我们的应用程序中,我们为不同的构建使用不同的口味,一个主包被两种口味使用。

我们在gradle中这样定义它:

    productFlavors {
mock {
applicationIdSuffix = ".mock"
}
prod {

}
flavour1 {
applicationIdSuffix = ".flavour1"
versionCode = 1
versionName "1.0." + versionCode
}
flavour2 {
applicationIdSuffix = ".flavour2"
versionCode = 2
versionName "1.0." + versionCode
}
}

带包:

-> src
---> flavour1
-----> java
-----> res
---> flavour2
-----> java
-----> res
---> main
-----> assets
-----> java
-----> res
-----> AndroidManifest.xml

基本 Activity/fragment 在“主要”中, flavor 共享 fragment/Activity 名称。我们还使用泛型,它们为此使用准备好的可扩展主类。

端点字符串在 res/strings 中,每个 flavor 都是分开的。

关于android gradle - 如何创建新的产品风格但重用另一种风格的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45897274/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com