如何与带有flutter应用程序的Admob集成?
实际上,我想在应用程序的底部显示Google Ads,这就是为什么我浏览它并得到tutorial并跟随其后的原因,但不知道为什么它无法正常工作.. !!! 遇到问题,我无法抓住, 我搜索了此问题,但找不到任何解决方法
Widget build(BuildContext context) {
FirebaseAdMob.instance.initialize(appId: "ca-app-pub-3280358404648281~7983595363");
myBanner..load()..show();
return Scaffold(
.....
);
}
}
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['game', 'babilok'],
contentUrl: 'https://flutter.io',
birthday: DateTime.now(), //deprecated
childDirected: false,
designedForFamilies: false, //deprecated
gender: MobileAdGender.male, // or MobileAdGender.female, MobileAdGender.unknown (deprecated)
testDevices: <String>[], // Android emulators are considered test devices
);
BannerAd myBanner = BannerAd(
// 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: "ca-app-pub-3280358404648281/6455246498",
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);
AndroidManifest.xml
<manifest
<application
<activity
....
</activity>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3280358404648281~*********"/>
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true"/>
</application>
</manifest>
控制台日志:
D/DynamitePackage( 3049): Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl
I/WebViewFactory( 3049): Loading com.google.android.webview version 76.0.3809.132 (code 380913205)
D/ResourcesManager( 3049): creating new AssetManager and set to /data/app/com.google.android.webview-2/base.apk
I/cr_LibraryLoader( 3049): Time to load native libraries: 2 ms (timestamps 3902-3904)
I/chromium( 3049): [INFO:library_loader_hooks.cc(51)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader( 3049): Expected native library version number "76.0.3809.132", actual native library version number "76.0.3809.132"
I/cr_BrowserStartup( 3049): Initializing chromium process, singleProcess=true
D/ConnectivityManager.CallbackHandler( 3049): CM callback handler got msg 524290
E/libEGL ( 3049): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
E/chromium( 3049): [ERROR:gl_surface_egl.cc(343)] eglChooseConfig failed with error EGL_BAD_ATTRIBUTE
W/cr_media( 3049): Requires BLUETOOTH permission
D/DynamitePackage( 3049): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
E/chromium( 3049): [ERROR:gl_surface_egl.cc(343)] eglChooseConfig failed with error EGL_BAD_ATTRIBUTE
I/Ads ( 3049): Use AdRequest.Builder.addTestDevice("C93E3D5EBB200061812734814B28CC4D") to get test ads on this device.
W/AudioCapabilities( 3049): Unsupported mime audio/mpeg-L1
W/AudioCapabilities( 3049): Unsupported mime audio/mpeg-L2
W/AudioCapabilities( 3049): Unsupported mime audio/x-ms-wma
W/AudioCapabilities( 3049): Unsupported mime audio/x-ima
W/VideoCapabilities( 3049): Unrecognized profile/level 32768/2 for video/mp4v-es
W/VideoCapabilities( 3049): Unsupported mime video/wvc1
W/VideoCapabilities( 3049): Unsupported mime video/x-ms-wmv
W/VideoCapabilities( 3049): Unrecognized profile/level 32768/2 for video/mp4v-es
W/VideoCapabilities( 3049): Unsupported mime video/wvc1
W/VideoCapabilities( 3049): Unsupported mime video/x-ms-wmv
W/VideoCapabilities( 3049): Unsupported mime video/x-ms-wmv7
W/VideoCapabilities( 3049): Unsupported mime video/x-ms-wmv8
W/VideoCapabilities( 3049): Unsupported mime video/sorenson
W/VideoCapabilities( 3049): Unsupported mime video/mp43
W/VideoCapabilities( 3049): Unrecognized profile/level 32768/2 for video/mp4v-es
I/VideoCapabilities( 3049): Unsupported profile 4 for video/mp4v-es
W/AudioCapabilities( 3049): Unsupported mime audio/ac3
W/art ( 3049): mismatched stack depths (depth=1, incoming depth=2)
I/DynamiteModule( 3049): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:20461
I/DynamiteModule( 3049): Selected remote version of com.google.android.gms.ads.dynamite, version >= 20461
D/ConnectivityManager.CallbackHandler( 3049): CM callback handler got msg 524290
E/IMGSRV ( 3049): :0: ComputeFrameBufferCompleteness: Switching psTex 0x8c777840 to XBGR
E/IMGSRV ( 3049): :0: ComputeFrameBufferCompleteness: Switching psLevel 0x9f1e0800 to XBGR
E/IMGSRV ( 3049): :0: ComputeFrameBufferCompleteness: Switching psTex 0x8c7778e0 to XBGR
E/IMGSRV ( 3049): :0: ComputeFrameBufferCompleteness: Switching psLevel 0x8c74f000 to XBGR
Syncing files to device GT I9500... 3,800ms (!)
E/FA ( 3049): GoogleService failed to initialize, status: 10, Missing google app id value from from string resources with name google_app_id.
W/art ( 3049): Suspending all threads took: 9.252ms
? To hot reload changes while running, press "r". To hot restart (and rebuild state), press "R".
An Observatory debugger and profiler on GT I9500 is available at: //http://127.0.0.1:65429/WyO_d_pLZrY=/
For a more detailed help message, press "h". To detach, press "d"; to quit, press "q".
I/FA ( 3049): App measurement is starting up, version: 14711
I/FA ( 3049): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
I/FA ( 3049): To enable faster debug mode event logging run:
I/FA ( 3049): adb shell setprop debug.firebase.analytics.app com.example.google_fire_admob
E/FA ( 3049): Missing google_app_id. Firebase Analytics disabled.
E/FA ( 3049): Uploading is not possible. App measurement disabled
W/Ads ( 3049): Not retrying to fetch app settings
W/flutter ( 3049): onAdFailedToLoad: 0
I/Ads ( 3049): Ad failed to load : 0
I/flutter ( 3049): BannerAd event is MobileAdEvent.failedToLoad
I/FA ( 3049): Tag Manager is not found and thus will not be used
E/FA ( 3049): Missing google_app_id. Firebase Analytics disabled.
I/Timeline( 3049): Timeline: Activity_idle id: android.os.BinderProxy@2669e1b1 time:9049317
E/FA ( 3049): Missing google_app_id. Firebase Analytics disabled.
V/ActivityThread( 3049): updateVisibility : ActivityRecord{50bb604 token=android.os.BinderProxy@2669e1b1 {com.example.google_fire_admob/com.example.google_fire_admob.MainActivity}} show : true
答案 0 :(得分:0)
您需要添加google-service.json。如果您不知道如何找到此JSON。请按照以下步骤;
您可以从here
中找到更多信息。最后,请使用测试广告单元ID进行测试。 Admob不能快速填写新的单位ID。
答案 1 :(得分:0)
可能是因为与您链接到的教程不同,您在myBanner..load()..show();
完成之前调用了FirebaseAdMob.instance.initialize
。尝试将.then((_) { myBanner..load()..show(); });
链接到初始化调用。