多个 Gradle productFlavors
Multiple Gradle productFlavors
我正在开发一个 Android 应用程序,其中包含两个 'skins' 和两种 'builds':
productFlavors {
Staging {
dimension "server"
buildConfigField 'String', 'API', "the staging API URL"
}
Production {
dimension "server"
buildConfigField 'String', 'API', "the production API URL"
}
SkinOne {
dimension "skin"
// Use default API URL
}
SkinTwo {
dimension "skin"
// Set a specific staging/production API URL
// if buildVariant.contains("Staging") -> set staging URL
// else if buildVariant.contains("Production") -> set production URL
}
}
问题是当我 select 使用 SkinTwo[=24 的构建变体时,我想 更改 te API 字符串=].
这在 Gradle 中可行吗?还是我必须在 BuildConfig class 中解决这个问题?
我已经尝试了 this variantFilter
但那行不通。
我已经修复了它:
productFlavors {
Staging {
dimension "server"
}
Production {
dimension "server"
}
SkinOne {
dimension "skin"
}
SkinTwo {
dimension "skin"
}
}
applicationVariants.all { variant ->
if (variant.getName().contains("StagingSkinOne")) {
variant.buildConfigField 'String', 'API', "staging URL"
} else if (variant.getName().contains("ProductionSkinOne")) {
variant.buildConfigField "String", "API", "production URL"
} else if (variant.getName().contains("StagingSkinTwo")) {
variant.buildConfigField "String", "API", "the specific staging URL"
} else if (variant.getName().contains("ProductionSkinTwo")) {
variant.buildConfigField "String", "API", "the specific production URL"
}
}
我正在开发一个 Android 应用程序,其中包含两个 'skins' 和两种 'builds':
productFlavors {
Staging {
dimension "server"
buildConfigField 'String', 'API', "the staging API URL"
}
Production {
dimension "server"
buildConfigField 'String', 'API', "the production API URL"
}
SkinOne {
dimension "skin"
// Use default API URL
}
SkinTwo {
dimension "skin"
// Set a specific staging/production API URL
// if buildVariant.contains("Staging") -> set staging URL
// else if buildVariant.contains("Production") -> set production URL
}
}
问题是当我 select 使用 SkinTwo[=24 的构建变体时,我想 更改 te API 字符串=].
这在 Gradle 中可行吗?还是我必须在 BuildConfig class 中解决这个问题?
我已经尝试了 this variantFilter
但那行不通。
我已经修复了它:
productFlavors {
Staging {
dimension "server"
}
Production {
dimension "server"
}
SkinOne {
dimension "skin"
}
SkinTwo {
dimension "skin"
}
}
applicationVariants.all { variant ->
if (variant.getName().contains("StagingSkinOne")) {
variant.buildConfigField 'String', 'API', "staging URL"
} else if (variant.getName().contains("ProductionSkinOne")) {
variant.buildConfigField "String", "API", "production URL"
} else if (variant.getName().contains("StagingSkinTwo")) {
variant.buildConfigField "String", "API", "the specific staging URL"
} else if (variant.getName().contains("ProductionSkinTwo")) {
variant.buildConfigField "String", "API", "the specific production URL"
}
}