0
0

Flutterでadmobをandroidに追加するための備忘録

Posted at

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0