Reputation: 2906
https://pub.dev/packages/google_mobile_ads
I copied this example
and everything is working fine except "Native Ad"
Of course, MainActivity.kt and NativeAdFactoryExample.kt are all set perfectly
and of course I used testAdUnitId for NativeAd
but it keeps show
I/Ads ( 6932): Received log message: <Google:HTML> Incorrect native ad response. Click actions were not properly specified
I/Ads ( 6932): Ad failed to load : 0
I/flutter ( 6932): NativeAd failedToLoad: LoadAdError(code: 0, domain: com.google.android.gms.ads, message: Internal error.)
I`m working on it for 12hours and it`s still not solved and I am really getting crazy
Could anyone help this problem please?
Upvotes: 2
Views: 3554
Reputation: 2428
So i came up against this and could not get it to work until i found this https://github.com/googleads/googleads-mobile-flutter/issues/399 so making your ad widget use the auto keep alive mixin apparently helps, i tried that with my code and it would not work i then used the example in the link which did work, the only difference i can see is he is creating an instance of the ad in init state and then calling .load() on that instance, where as i was using the dart notation and creating the instance and calling ..load() in the same call Object()..load() i think these things are usually identical but i switched to his version and it worked. Below is the example the only i thing i swapped was the style from using the factoryId to specifying a style
class NativeInlineAd extends StatefulWidget {
const NativeInlineAd();
@override
State createState() => _NativeInlineAdState();
}
class _NativeInlineAdState extends State<NativeInlineAd>
with AutomaticKeepAliveClientMixin {
// COMPLETE: Add NativeAd instance
late NativeAd _ad;
// COMPLETE: Add _isAdLoaded
bool _isAdLoaded = false;
@override
void initState() {
super.initState();
// COMPLETE: Create a NativeAd instance
_ad = NativeAd(
adUnitId: kReleaseMode
? '<YOUR_NATIVE_ADMOB_ID>'
: '<NATIVE_TEST_AD_ID>',
factoryId: 'googleNativeAdsCard',
request: const AdRequest(),
listener: NativeAdListener(
onAdLoaded: (_) {
setState(() {
_isAdLoaded = true;
});
},
onAdFailedToLoad: (ad, error) {
// Releases an ad resource when it fails to load
ad.dispose();
throw 'Ad load failed (code=${error.code} message=${error.message})';
},
),
);
// COMPLETE: Load an ad
_ad.load();
}
@override
Widget build(BuildContext context) {
super.build(context);
if (_isAdLoaded) {
return Container(
child: SizedBox(height: 200, child: AdWidget(ad: _ad)),
),
height: 270,
margin: const EdgeInsets.only(
left: 10,
right: 10,
top: 5,
),
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
ValuesConstant.borderRadius,
),
border: Border.all(
width: 1,
color: Colors.black,
),
color: Theme.of(context).cardTheme.color,
),
alignment: Alignment.center,
);
}
return const SizedBox(
height: 72.0,
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.grey,
),
),
),
);
}
@override
void dispose() {
_ad.dispose();
super.dispose();
}
@override
bool get wantKeepAlive => true;
}
Upvotes: 0
Reputation: 1252
if your code is fine and also you are using an emulator with google play. just set your app-ads.txt which can be found in your all apps on google AdMob
Google will crawl the URL (root URL of your website) and find these apps requesting or serving ads.
Upvotes: 0
Reputation: 4277
If your code is OK, then nothing to worry about. just try again on other emulator with "google play" or try with live device.
Upvotes: 3