flutter firebase_admob integration - how to use it along with app flavors
I use google_mobile_ads plugin with flavors. Here's how I set up for different flavors:
in my android/app/build.gradle, I simply add resValue named ads_id
productFlavors{
ss {
dimension "flavor-type"
applicationId "com.company.ss"
resValue "string", "app_name", "ss"
resValue "string", "ads_id", "ca-app-pub-xxx~yy"
versionNameSuffix "-ss"
signingConfig signingConfigs.ss
}
rk {
dimension "flavor-type"
applicationId "com.company.rk"
resValue "string", "app_name", "rk"
resValue "string", "ads_id", "ca-app-pub-xxx~yy"
versionNameSuffix "-rk"
signingConfig signingConfigs.rk
}
ns {
dimension "flavor-type"
applicationId "com.company.ns"
resValue "string", "app_name", "ns"
resValue "string", "ads_id", "ca-app-pub-xxxx~yyy"
versionNameSuffix "-ns"
signingConfig signingConfigs.ns
}
}
and then grab this value inside AndroidManifest.xml
<application
android:name="io.flutter.app.FlutterApplication"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:icon="@mipmap/launcher_icon">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/ads_id"/>
<activity
..
Angel Todorov
Updated on December 10, 2022Comments
-
Angel Todorov over 1 year
I have my flutter app setup to use flavors for different releases e.g. development, production and etc. The essential part of this lays into app/build.gradle file and looks like that:
flavorDimensions "flutter-flavours" productFlavors { development { dimension "flutter-flavours" applicationIdSuffix ".dev" } staging { dimension "flutter-flavours" applicationIdSuffix ".stg" } production { dimension "flutter-flavours" }
As a result, when I build let's say development release, I have got it with following appId -
com.example.myapp.dev
, while my production release iscom.example.myapp
. So far so good.Now, I decided to add a firebase_admob plugin to the app. To do so, I made Firebase app into my Firebase account and downloaded corresponding
google-services.json
file required for authentication. Then, I have to put this file into an android/app folder of my app.And this is where I found a bummer - basically, I can create
json
file for each of the app flavor, i.e. I can have one json for production and one for development, but I cannot figure out how to put these both into the folder and how gradle will figure out which one to take according to the release flavor.Any thoughts, hints would be greatly appreciated!