Reputation: 103
For an existing app that's moving over to firebase I'm trying to set up a development build and a production build. I'm using two different projects in firebase and as such have two different google.services.json. I'm mostly followed this example.
Stripped Gradle file, note the buildTypes & productFlavors :
android {
compileSdkVersion 28
defaultConfig {
applicationId "nl.my_project.cwo_app"
(...)
}
buildTypes {
release {
}
debug {
applicationIdSuffix ".debug"
}
}
// This is used to ensure the right version of google-services.json is used.
flavorDimensions "version"
productFlavors {
dev {
dimension "version"
versionNameSuffix "-dev"
}
prod {
dimension "version"
versionNameSuffix "-prod"
}
}
}
dependencies {
...
}
I have the following directory structure:
app/
src/
main/
dev/
google-services.json (for dev only)
prod/
google-services.json (for prod only)
As far as I understand this should make sure that once I build anything with the dev flavor that it uses the google-services.json in the dev folder. But when I build the project (after selecting a build variant, for example devDebug) it gives an error saying the application ID does not fit. Looking into this shows that in fact BOTH google-services.json are being used. How can I change this?
The build log:
14:00:55: Executing task 'build'...
Executing tasks: [build]
> Configure project :app
> Task :app:preBuild UP-TO-DATE
> Task :app:preDevDebugBuild UP-TO-DATE
> Task :app:compileDevDebugAidl NO-SOURCE
(...)
> Task :app:processDevDebugGoogleServices
Parsing json file: E:\projecten\CWO_app\app\src\dev\google-services.json
(...)
> Task :app:processProdDebugGoogleServices FAILED
Parsing json file: E:\projecten\CWO_app\app\src\prod\google-services.json
FAILURE: Build failed with an exception.
Execution failed for task ':app:processProdDebugGoogleServices'.
> No matching client found for package name 'nl.my_project.cwo_app.debug'
As you can see it creates a version with the applicationIdSuffix ".debug" and then tries to match that to the file in the 'prod' folder, which doesn't use that applicationId. How can I stop it from looking at both folders?
Upvotes: 1
Views: 1074
Reputation: 173
The problem relays on the combination between flavor and release names. According to the provided gradle file, when the build type is "debug", then the suffix .debug
is added, hence if your google-services.json
file doesn't have the declared resulting package name, then will fail.
The available package name combinations are:
nl.my_project.cwo_app.debug
(for debug build type)nl.my_project.cwo_app
(for release build type)How to fix this
Check in your google-services.json
the available package names. If any of the combinations described above are not declared there, then add them from the Firebase console and update the new json file into your project.
Tip:
You can have one single google-services.json
file with all the package names in it instead of having one file per combination of flavor and/or build. Regularly, this is more neat in terms of maintainability (one file vs build types * number of flavors)
Upvotes: 0