gpt4 book ai didi

android - 无法使用 flutter 项目在测试设备(模拟器)上加载测试广告

转载 作者:IT王子 更新时间:2023-10-29 06:58:25 26 4
gpt4 key购买 nike

我是 Flutter 应用项目的新手。我根据 https://firebase.google.com/docs/android/setup 配置了我的应用程序

输出控制台

Launching lib\main.dart on Android SDK built for x86 in debug mode...Initializing gradle...Resolving dependencies...Running Gradle task 'assembleDebug'...registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)Built build\app\outputs\apk\debug\app-debug.apk.D/NetworkSecurityConfig(17748): No Network Security Config specified, using platform defaultI/WebViewFactory(17748): Loading com.android.chrome version 69.0.3497.100 (code 349710017)I/jokes.jokespun(17748): The ClassLoaderContext is a special shared library.I/jokes.jokespun(17748): The ClassLoaderContext is a special shared library.Syncing files to device Android SDK built for x86...I/jokes.jokespun(17748): Background concurrent copying GC freed 14545(2MB) AllocSpace objects, 9(176KB) LOS objects, 50% free, 1808KB/3MB, paused 5.468ms total 87.502msI/cr_LibraryLoader(17748): Time to load native libraries: 19 ms (timestamps 870-889)I/chromium(17748): [INFO:library_loader_hooks.cc(36)] Chromium logging enabled: level = 0, default verbosity = 0I/cr_LibraryLoader(17748): Expected native library version number "69.0.3497.100", actual native library version number "69.0.3497.100"W/cr_ChildProcLH(17748): Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = trueI/cr_BrowserStartup(17748): Initializing chromium process, singleProcess=falseI/chromium(17748): [INFO:aw_field_trial_creator.cc(54)] First-WebView-Experiment not foundI/FA      (17748): Tag Manager is not found and thus will not be usedI/OpenGLRenderer(17748): Initialized EGL, version 1.4D/OpenGLRenderer(17748): Swap behavior 1D/        (17748): HostConnection::get() New Host Connection established 0xc27781c0, tid 17839W/OpenGLRenderer(17748): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...D/OpenGLRenderer(17748): Swap behavior 0D/EGL_emulation(17748): eglCreateContext: 0xe06ee060: maj 3 min 0 rcv 3W/jokes.jokespun(17748): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)D/EGL_emulation(17748): eglMakeCurrent: 0xe06ee060: ver 3 0 (tinfo 0xc2737970)D/EGL_emulation(17748): eglCreateContext: 0xe06eed20: maj 3 min 0 rcv 3D/EGL_emulation(17748): eglMakeCurrent: 0xe06eed20: ver 3 0 (tinfo 0xe076e4e0)V/FA      (17748): Deferring to Google Analytics for Firebase for event data collection.D/DynamitePackage(17748): Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImplI/DynamiteModule(17748): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:11140I/DynamiteModule(17748): Selected remote version of com.google.android.gms.ads.dynamite, version >= 11140V/DynamiteModule(17748): Dynamite loader version >= 2, using loadModule2NoCrashUtilsD/DynamitePackage(17748): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImplI/Ads     (17748): Starting ad request.I/Ads     (17748): SDK version: afma-sdk-a-v15090040.14300000.1I/Ads     (17748): This request is sent from a test device.W/Ads     (17748): Could not find com.google.android.gms.ads.AdActivity, please make sure it is declared in AndroidManifest.xml.I/Choreographer(17748): Skipped 39 frames!  The application may be doing too much work on its main thread.D/EGL_emulation(17748): eglMakeCurrent: 0xe06ee060: ver 3 0 (tinfo 0xc2737970)I/OpenGLRenderer(17748): Davey! duration=826ms; Flags=1, IntendedVsync=15091144858940, Vsync=15091794858914, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15091808987960, AnimationStart=15091809076260, PerformTraversalsStart=15091809263460, DrawStart=15091820381260, SyncQueued=15091822369660, SyncStart=15091827238560, IssueDrawCommandsStart=15091833671660, SwapBuffers=15091871677860, FrameCompleted=15091976321160, DequeueBufferDuration=59743000, QueueBufferDuration=370000, W/cr_CrashFileManager(17748): /data/user/0/puns.jokes.jokespuns/cache/WebView/Crash Reports does not exist or is not a directoryD/        (17748): HostConnection::get() New Host Connection established 0xdf4d9a00, tid 17773D/EGL_emulation(17748): eglMakeCurrent: 0xe06eed20: ver 3 0 (tinfo 0xe076e710)D/skia    (17748): Program linking failed.I/chatty  (17748): uid=10086(puns.jokes.jokespuns) 1.gpu identical 7 linesD/skia    (17748): Program linking failed.D/skia    (17748): Program linking failed.

I am trying to include AdMob in my flutter project for Android.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="puns.jokes.package.unique">

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Jokes and Puns"
android:icon="@mipmap/ic_launcher">

<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-<appid>"/>
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

Build.gradle

buildscript {
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
}
}allprojects {
repositories {
google()
jcenter()
}
}rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}subprojects {
project.evaluationDependsOn(':app')
}task clean(type: Delete) {
delete rootProject.buildDir}

App/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 = '2.0.0'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '2.0.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
compileSdkVersion 28

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "puns.jokes.jokespuns"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-ads:17.1.3'
implementation 'com.google.android.gms:play-services-ads:17.1.3'
// testImplementation 'junit:junit:4.12'
// androidTestImplementation 'com.android.support.test:runner:1.0.2'
// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

主屏幕.dart

@override
void initState() {
super.initState();
FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
}
@override
Widget build(BuildContext context) {
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
testDevices: <String>[], // Android emulators are considered test devices
);

myInterstitial = InterstitialAd(
// Replace the testAdUnitId with an ad unit id from the AdMob dash.
// https://developers.google.com/admob/android/test-ads
// https://developers.google.com/admob/ios/test-ads
adUnitId: InterstitialAd.testAdUnitId,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("InterstitialAd event is $event");
},
);
myInterstitial..load()..show();
}

.....
.....
.....
.....
.....
@override
void dispose() {
myInterstitial.dispose();
super.dispose();
}

没有任何错误或警告的广告。

最佳答案

将这部分移到 Activity 之外

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-<appid>"/>

关于android - 无法使用 flutter 项目在测试设备(模拟器)上加载测试广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54754293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com