google_mobile_adsのインストール
pubspec.yamlに以下の行を追加する
dependencies:
google_mobile_ads: ^4.0.0
google_mobile_adsの初期化
main.dart
import 'dart:async';
import 'package:google_mobile_ads/google_mobile_ads.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
unawaited(MobileAds.instance.initialize());//これを追加
runApp(const MyApp());
}
広告の読み込み等
下のサイトのexampleを参考にすれば、すぐに実装できる。
https://pub.dev/packages/google_mobile_ads/example
なんかビルドで失敗する
多分、google_mobile_adsを加えると, androidの64k問題に到達する。
下のサイトに従って、flutter run --debug
を行えば、簡単にmultidexに対応できるので、変にbuild.gradleとかいじらないこと。
https://docs.flutter.dev/deployment/android#enabling-multidex-support