Android (Java) way:
Minimal reproducible code:
public class MainActivity extends Activity {
private static final String TAG = "MyTag";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(this);
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this, "ca-app-pub-3940256099942544/1033173712", adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
Log.i(TAG, "onAdLoaded");
interstitialAd.show(MainActivity.this);
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
Log.i(TAG, loadAdError.getMessage());
}
});
}
}
My build.gradle(app)
implementation 'com.google.android.gms:play-services-ads:20.2.0'
My AndroidManifest.xml
:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
Problem (on Android):
Even using the test Ad ID and test App ID, the ads are not loading up.
Flutter (Dart) way:
Minimal reproducible code:
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => MyAppState();
}
class MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
InterstitialAd.load(
adUnitId: 'ca-app-pub-3940256099942544/1033173712',
request: AdRequest(),
adLoadCallback: InterstitialAdLoadCallback(
onAdLoaded: (ad) => ad.show(),
onAdFailedToLoad: (e) => print('Failed: $e'),
),
);
}
@override
Widget build(BuildContext context) => Container();
}
Problem (on Flutter):
The test ads show up but when I try to use my own Ad ID and App ID (even in the release mode), it fails with this error.
No ad config.
It's been a week now since I created that ad unit on Admob. I also have a different app on the Play Store (which is showing ad) but even if I use that app's ID in my code, it fails to load the ad with error code 3.
PS: Tried this solution already but it didn't work.