我正在尝试根据 android 项目中的不同风格实现多个 google-service.json 文件。我曾尝试使用以下代码:https ://medium.com/google-cloud/automatic-per-variant-google-services-json-configurations-with-gradle-d3d3e40abc0e
下面是我同时拥有 google-service.json 文件的路径-
app/flavourA/google-services.json
app/flavourB/google-services.json
在 app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions"default"
productFlavors {
flavourA {
buildConfigField("String", "flavored_app_name", "\"flavourA\"")
buildConfigField("String", "ApplicationId", "\"com.companyname.flavourA\"")
applicationId 'com.companyname.flavourA'
dimension "default"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
versionCode 68
versionName '3.1.7'
}
flavourB{
versionCode 14
buildConfigField("String", "flavored_app_name", "\"flavourB\"")
buildConfigField("String", "ApplicationId", "\"com.companyname.flavourB\"")
applicationId 'com.companyname.flavourB'
dimension "default"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
versionName '1.7.0'
}
}
}
def appModuleRootFolder = '.'
def srcDir = 'src'
def googleServicesJson = 'google-services.json'
task switchToDebug(type: Copy) {
def buildType = 'debug'
description = 'Switches to DEBUG google-services.json'
from "${srcDir}/${buildType}"
include "$googleServicesJson"
into "$appModuleRootFolder"
}
task switchToRelease(type: Copy) {
def buildType = 'release'
description = 'Switches to RELEASE google-services.json'
from "${srcDir}/${buildType}/"
include "$googleServicesJson"
into "$appModuleRootFolder"
}
afterEvaluate {
flavourA.dependsOn switchToDebug
flavourB.dependsOn switchToRelease
}
错误:
ERROR: Could not get unknown property 'flavourA' for project ':app' of type org.gradle.api.Project.