šAd for following adId already exists: 0
See original GitHub issueBug report
Describe the bug This error appears if I set the adUnitId to literally anything. Iāve tried setting the property to āhiā and a bunch of other stuff but it somehow still appears. And if I set it to a valid ad id it continues to appear and the ad never shows.
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): java.lang.IllegalArgumentException: Ad for following adId already exists: 0
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at io.flutter.plugins.googlemobileads.AdInstanceManager.trackAd(AdInstanceManager.java:66)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:266)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at android.os.MessageQueue.next(MessageQueue.java:335)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at android.os.Looper.loop(Looper.java:183)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/MethodChannel#plugins.flutter.io/google_mobile_ads( 6263): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter ( 6263): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, Ad for following adId already exists: 0, null, java.lang.IllegalArgumentException: Ad for following adId already exists: 0
E/flutter ( 6263): at io.flutter.plugins.googlemobileads.AdInstanceManager.trackAd(AdInstanceManager.java:66)
E/flutter ( 6263): at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:266)
E/flutter ( 6263): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter ( 6263): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter ( 6263): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/flutter ( 6263): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 6263): at android.os.MessageQueue.next(MessageQueue.java:335)
E/flutter ( 6263): at android.os.Looper.loop(Looper.java:183)
E/flutter ( 6263): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter ( 6263): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 6263): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter ( 6263): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter ( 6263): )
E/flutter ( 6263): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
E/flutter ( 6263): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
E/flutter ( 6263): <asynchronous suspension>
E/flutter ( 6263): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter ( 6263): #3 AdInstanceManager.loadNativeAd (package:google_mobile_ads/src/ad_instance_manager.dart:172:20)
E/flutter ( 6263): #4 NativeAd.load (package:google_mobile_ads/src/ad_containers.dart:576:27)
E/flutter ( 6263): #5 NativeAdState.initState.<anonymous closure> (package:discord_bots/widgets/global/native_ad_widget.dart:36:65)
E/flutter ( 6263): #6 new Future.delayed.<anonymous closure> (dart:async/future.dart:326:39)
E/flutter ( 6263): #7 _rootRun (dart:async/zone.dart:1182:47)
E/flutter ( 6263): #8 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 6263): #9 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 6263): #10 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 6263): #11 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 6263): #12 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 6263): #13 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter ( 6263): #14 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter ( 6263): #15 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter ( 6263): #16 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter ( 6263): #17 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter ( 6263):
Steps to reproduce
Steps to reproduce the behavior:
- Create a native ad widget
- Add the java files to the src folder and add the layout XML file to the res folder.
- Run app
Additional context
My code is from the example:
import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
class NativeAdWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() => NativeAdState();
}
class NativeAdState extends State<NativeAdWidget> {
NativeAd _nativeAd;
final Completer<NativeAd> nativeAdCompleter = Completer<NativeAd>();
@override
void initState() {
super.initState();
_nativeAd = NativeAd(
adUnitId: NativeAd.testAdUnitId,
request: AdRequest(),
factoryId: 'listTile',
listener: AdListener(
onAdLoaded: (Ad ad) {
print('$NativeAd loaded.');
nativeAdCompleter.complete(ad as NativeAd);
},
onAdFailedToLoad: (Ad ad, LoadAdError error) {
print('$NativeAd failedToLoad: $error');
nativeAdCompleter.completeError(null);
},
onAdOpened: (Ad ad) => print('$NativeAd onAdOpened.'),
onAdClosed: (Ad ad) => print('$NativeAd onAdClosed.'),
onApplicationExit: (Ad ad) => print('$NativeAd onApplicationExit.'),
),
);
Future<void>.delayed(Duration(seconds: 1), () => _nativeAd?.load());
}
@override
void dispose() {
super.dispose();
_nativeAd?.dispose();
_nativeAd = null;
}
@override
Widget build(BuildContext context) {
return FutureBuilder<NativeAd>(
future: nativeAdCompleter.future,
builder: (BuildContext context, AsyncSnapshot<NativeAd> snapshot) {
Widget child;
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
case ConnectionState.active:
child = Container();
break;
case ConnectionState.done:
if (snapshot.hasData) {
child = AdWidget(ad: _nativeAd);
} else {
child = Text('Error loading $NativeAd');
}
}
return Container(
width: 250,
height: 350,
child: child,
color: Colors.blueGrey,
);
},
);
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:13
- Comments:18
Top Results From Across the Web
Using test banner ad id in flutter throwing exception - "Ad for ...
I found out after research and testing that one unit ad needs a unique ad unit id. The unique identifier for an ad...
Read more >[Solved]-Ads failed to load while using banner test ads-Flutter
Coding example for the question Ads failed to load while using banner test ... id in flutter throwing exception - "Ad for following...
Read more >google_mobile_ads | Flutter Package - Pub.dev
Flutter plugin for Google Mobile Ads, supporting banner, interstitial (full-screen), rewarded and native ads.
Read more >Get a user-resettable advertising ID - Android Developers
Note: Because the user can reset their advertising ID after your app starts, you should call AdvertisingIdClient.getAdvertisingIdInfo() eachĀ ...
Read more >Banner Ads | Android - Google Developers
Note the following required attributes: ads:adSize - Set this to the ad size you'd like to use. If you don't want to use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ads are loading and displaying when I run the app on a device or in the simulator but will crash if I press the āRestartā button - not the āHot Reloadā button.
Error message:
The app crashes at the following line in the Widget: _bannerAd?.load();
Banner Widget code:
The crash on hot reload should be resolved in
0.11.0+4
, via https://github.com/googleads/googleads-mobile-flutter/pull/94.@WieFel If youāre having issue getting test ads to work could you open a separate issue?