【发布时间】:2022-08-08 19:07:12
【问题描述】:
我正在尝试将 AdMob 中介网络(特别是 Meta Audience Network)集成到 Flutter 中,我添加了“google_mobile_ads”包 (https://pub.dev/packages/google_mobile_ads)。
我想问两件事:
-
我遵循了最初的集成文档 (https://developers.google.com/admob/flutter/quick-start#platform_specific_setup),上面写着“有关配置 AndroidManifest.xml 和设置应用程序 ID 的更多信息,请参阅 Android 指南”。在该链接中,它显示了其他要执行的步骤,我应该执行这些步骤还是插件本身执行(iOS 的相同问题)? (我想知道为什么我现在还没有制作它们,而且它似乎有效)
-
如果我想添加 Meta Audience Network,我会转到文档 (https://developers.google.com/admob/android/mediation/meta#android_studio_integration_recommended),但我不明白我需要将该依赖项放在哪个 build.gradle 上。在我之前链接的“Get Started”中,google 和 mavenCentral 存储库被添加到 build.gradle 项目中,但是在中介网络的最后一个链接中,我需要在构建中添加依赖项。该应用程序的 gradle ,它还显示了我在 build.gradle 项目中拥有的 google 和 mavenCentral 存储库。 我对 Flutter 的两个 build.gradles 有点困惑,你能告诉我我需要在哪里添加依赖项吗?
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(应用程序)
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\" }附言。我也尝试联系官方支持,但他们回复说他们不处理这个(虽然我觉得很奇怪,实际上我回复了https://groups.google.com/g/google-admob-ads-sdk/c/gS9bAD1Y7FA)
标签: android flutter admob build.gradle facebook-audience-network