Reputation: 77752
I have two build types - debug
and release
- and two flavors, dev
and prod
.
The distinction is straightforward: debug
is a debuggable binary, release
is optimized, has debug code removed, and Proguard.
dev
is meant to connect to a development Firebase project, prod
is for the actual production database.
There are cases when I would like to use debug
in the prod database, so I have all four possible combinations. The problem is that the project settings in Firebase require the SHA1 fingerprint of the signing key of the binary, and creating a debuggable application will always use the debug key.
I can't have the same key on two Firebase projects, so having the debug signing key on the dev Firebase project means I can't also have it on the prod one, so I cannot use the "prodDebug" setup (i.e. prod database with a debuggable binary).
What's the proper way to resolve this?
Upvotes: 2
Views: 2839
Reputation: 77752
The missing element in the setup is outlined in the Medium article (link via the Wayback Machine) posted in Fazan Cheng's comment.
Firebase does not allow the same SHA1 key for the same application ID. That means we can work around this problem by modifying the application ID in each flavor.
Specifically, this can be done with applicationIdSuffix
, which add a string to the application ID. For example:
productFlavors {
dev {
applicationIdSuffix '.dev'
versionNameSuffix "-dev"
dimension 'env'
}
prod {
versionNameSuffix "-prod"
dimension 'env'
}
}
If your application ID is com.foo.myapplication
, the dev flavor will have the ID com.foo.myapplication.dev
. You can now generate a separate Firebase project with this new ID and re-use the same SHA1 keys.
Upvotes: 3
Reputation: 13347
You will need to have two different Firebase Projects with two different google.services.json
files. Both of them can have the same SHA
keys associated to the project. To make it work you will need put each one of the files in the right folder of the project.
app/src/
release/google-services.json
debug/google-services.json
In this way, when you will compile your project, depending if it's a release version or a debug one, you will compile the project against one database or another. If you want to use custom flavors you can do the same, changing relase and debug for the name of your flavors:
app/src/
flavor1/google-services.json
flavor2/google-services.json
flavor3/google-services.json
If you want more details about how this plugin work, give a look to: https://github.com/googlesamples/google-services/issues/54#issuecomment-165824720
Hope that it will help you!
Happy coding!
Upvotes: 1