I'm trying to integrate AdMob mediation networks (specifically Meta Audience Network) into Flutter, I added the "google_mobile_ads" package (https://pub.dev/packages/google_mobile_ads).
There are two things I would like to ask:
I followed the initial integration documentation (https://developers.google.com/admob/flutter/quick-start#platform_specific_setup) which says "See the Android guide for more information on configuring AndroidManifest.xml and setting app ID". In that link it shows other steps to do, should I do them or does the plugin itself (same question for iOS)? (I wonder why I haven't made them at the moment and it seems to work)
If I want to add Meta Audience Network, I go to the documentation (https://developers.google.com/admob/android/mediation/meta#android_studio_integration_recommended), but I don't understand which build.gradle I need to put that dependency on. In the "Get Started" that I linked earlier, the google and mavenCentral repositories are added in the build.gradle project, but in this last link of the mediation network it is written that I need to add the dependency in the build.gradle of the app and it also shows the google and mavenCentral repositories which I have in the build.gradle project. I get a little confused with Flutter's two build.gradles, could you tell me where I need to add the dependencies?
build.gradle (progetto)
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (app)
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs = 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "my_application_id"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 19
targetSdkVersion flutter.targetSdkVersion
multiDexEnabled true
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.multidex:multidex:2.0.1"
}
ps. I also tried to contact official support but they replied that they don't deal with this (although it seems strange to me, in fact I replied https://groups.google.com/g/google-admob-ads-sdk/c/gS9bAD1Y7FA)
CodePudding user response:
Yes you have to do this to prevent ads limitation or some issues in the future
All you need to do is add
implementation 'com.google.ads.mediation:facebook:6.11.0.1'
in build.gradle (app)
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.multidex:multidex:2.0.1"
//Here
implementation 'com.google.ads.mediation:facebook:6.11.0.1'
}