LoginSignup
1
2

More than 1 year has passed since last update.

google_mobile_adsをインストールしたら、アプリがクラッシュするようになった...

Last updated at Posted at 2021-11-13

突然クラッシュするようになりました...

Flutterで開発を進めていたところ、前日まで普通にビルドできていたのに突然、If you do NOT see the Flutter application running, it might have crashedというエラーに遭遇しました。iOSシュミレータでデバッグした結果です。

Launching lib/main.dart on iPhone 12 in debug mode...
Running pod install...
Running Xcode build...
Xcode build done.                                           390.1s
Connecting to the VM Service is taking longer than expected...
Still attempting to connect to the VM Service...
If you do NOT see the Flutter application running, it might have crashed. The device logs (e.g. from adb or XCode) might have more details.
If you do see the Flutter application running on the device, try re-running with --host-vmservice-port to use a specific port known to be available.
Exception attempting to connect to the VM Service: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 54372
This was attempt #50. Will retry in 0:00:01.600000.
Exception attempting to connect to the VM Service: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 54473
This was attempt #100. Will retry in 0:00:01.600000.
Exception attempting to connect to the VM Service: SocketException: OS Error: Connection refused, errno = 61, address = 127.0.0.1, port = 54564

色々試しても解決しないので、気分転換にAndroidのエミュレータでビルドしてみたところ、以下のように、GoogleMobileAdSDKが正しくイニシャライズされていませんという内容が返ってきました。

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
E/AndroidRuntime(16955): FATAL EXCEPTION: main
E/AndroidRuntime(16955): Process: com.to2yama.gym_post.dev, PID: 16955
E/AndroidRuntime(16955): java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 
E/AndroidRuntime(16955): 
E/AndroidRuntime(16955): ******************************************************************************
E/AndroidRuntime(16955): * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
E/AndroidRuntime(16955): * should follow the instructions here:                                       *
E/AndroidRuntime(16955): * https://googlemobileadssdk.page.link/admob-android-update-manifest         *
E/AndroidRuntime(16955): * to add a valid App ID inside the AndroidManifest.                          *
E/AndroidRuntime(16955): * Google Ad Manager publishers should follow instructions here:              *
E/AndroidRuntime(16955): * https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
E/AndroidRuntime(16955): ******************************************************************************

google_mobile_adsはインストールだけだとクラッシュする

このアプリには広告を入れようと思っていて、google_mobile_adsのインストールだけをしておきました。広告導入のための設定は後回しにしていたのですが、実はその設定をしないとアプリがクラッシュする仕様になっていたみたいです。pub.devを見るとAndroidについて以下の記載がありました(iOSの方では、クラッシュについての記載は見つけられませんでした)。

The AdMob App ID must be included in the AndroidManifest.xml. Failure to do so will result in a crash on launch of an app.
(AdMobアプリIDはAndroidManifest.xmlに含まれている必要があります。そうしないと、アプリの起動時にクラッシュが発生します。)

対処法

スクリーンショット 2021-11-13 20.46.50.png
一旦google_mobile_adsをコメントアウトしてPub getしたところ、うまくビルドが通るようになりました

もしくは、それぞれの広告設定を怠らなければうまくできていたと思います...
明日やろうは馬鹿野郎ってことですね...😓

👉iosアプリに広告を導入するための設定
👉Androidアプリに広告を導入するための設定

1
2
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
1
2