🛠️

[Flutter] flutterのwebView関連で発生したクラッシュ対策のメモ

2024/08/19に公開

ひとつひとつを記事にするのが難しいため、自分用のメモ書きとして
flutter関連で発生した調査が困難だったエラーと、その対処方法を書いておきます。
とりあえず2024/08/19時点での情報なので、ライブラリの更新によって直っている可能性もあります。

AndroidでWebViewを表示するとクラッシュする

以下のようなエラーが発生

D/InAppWebView(13364): Using InAppWebViewClientCompat implementation
W/cr_WebSettings(13364): setForceDark() is a no-op in an app with targetSdkVersion>=T
W/cr_SupportWebSettings(13364): setForceDarkBehavior() is a no-op in an app with targetSdkVersion>=T
E/MethodChannel#flutter/platform_views(13364): Failed to handle method call
E/MethodChannel#flutter/platform_views(13364): java.lang.RuntimeException: Unknown feature SUPPRESS_ERROR_PAGE
E/MethodChannel#flutter/platform_views(13364): 	at androidx.webkit.internal.WebViewFeatureInternal.isSupported(WebViewFeatureInternal.java:649)
E/MethodChannel#flutter/platform_views(13364): 	at androidx.webkit.internal.WebViewFeatureInternal.isSupported(WebViewFeatureInternal.java:618)
E/MethodChannel#flutter/platform_views(13364): 	at androidx.webkit.WebViewFeature.isFeatureSupported(WebViewFeature.java:611)
E/MethodChannel#flutter/platform_views(13364): 	at com.pichillilorenzo.flutter_inappwebview_android.webview.in_app_webview.InAppWebView.prepare(InAppWebView.java:436)
E/MethodChannel#flutter/platform_views(13364): 	at com.pichillilorenzo.flutter_inappwebview_android.webview.in_app_webview.FlutterWebView.<init>(FlutterWebView.java:82)
E/MethodChannel#flutter/platform_views(13364): 	at com.pichillilorenzo.flutter_inappwebview_android.webview.FlutterWebViewFactory.create(FlutterWebViewFactory.java:67)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:523)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.plugin.platform.PlatformViewsController$1.createForPlatformViewLayer(PlatformViewsController.java:168)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:105)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#flutter/platform_views(13364): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
E/MethodChannel#flutter/platform_views(13364): 	at android.os.Handler.handleCallback(Handler.java:958)
E/MethodChannel#flutter/platform_views(13364): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#flutter/platform_views(13364): 	at android.os.Looper.loopOnce(Looper.java:205)
E/MethodChannel#flutter/platform_views(13364): 	at android.os.Looper.loop(Looper.java:294)
E/MethodChannel#flutter/platform_views(13364): 	at android.app.ActivityThread.main(ActivityThread.java:8177)
E/MethodChannel#flutter/platform_views(13364): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter/platform_views(13364): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/MethodChannel#flutter/platform_views(13364): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/flutter (13364): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Unknown feature SUPPRESS_ERROR_PAGE, null, java.lang.RuntimeException: Unknown feature SUPPRESS_ERROR_PAGE
E/flutter (13364): 	at androidx.webkit.internal.WebViewFeatureInternal.isSupported(WebViewFeatureInternal.java:649)
E/flutter (13364): 	at androidx.webkit.internal.WebViewFeatureInternal.isSupported(WebViewFeatureInternal.java:618)
E/flutter (13364): 	at androidx.webkit.WebViewFeature.isFeatureSupported(WebViewFeature.java:611)
E/flutter (13364): 	at com.pichillilorenzo.flutter_inappwebview_android.webview.in_app_webview.InAppWebView.prepare(InAppWebView.java:436)
E/flutter (13364): 	at com.pichillilorenzo.flutter_inappwebview_android.webview.in_app_webview.FlutterWebView.<init>(FlutterWebView.java:82)
E/flutter (13364): 	at com.pichillilorenzo.flutter_inappwebview_android.webview.FlutterWebViewFactory.create(FlutterWebViewFactory.java:67)
E/flutter (13364): 	at io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:523)
E/flutter (13364): 	at io.flutter.plugin.platform.PlatformViewsController$1.createForPlatformViewLayer(PlatformViewsController.java:168)
E/flutter (13364): 	at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:105)
E/flutter (13364): 	at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55)
E/flutter (13364): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/flutter (13364): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/flutter (13364): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (13364): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
E/flutter (13364): 	at android.os.Handler.handleCallback(Handler.java:958)
E/flutter (13364): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (13364): 	at android.os.Looper.loopOnce(Looper.java:205)
E/flutter (13364): 	at android.os.Looper.loop(Looper.java:294)
E/flutter (13364): 	at android.app.ActivityThread.main(ActivityThread.java:8177)
E/flutter (13364): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (13364): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/flutter (13364): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/flutter (13364): )
E/flutter (13364): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7)
E/flutter (13364): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter (13364): <asynchronous suspension>
E/flutter (13364): #2      ExpensiveAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1104:5)
E/flutter (13364): <asynchronous suspension>
E/flutter (13364): #3      AndroidViewController.create (package:flutter/src/services/platform_views.dart:827:5)
E/flutter (13364): <asynchronous suspension>
E/flutter (13364): 

======== Exception caught by image resource service ================================================

これはwebview_flutter_androidによるエラーで、自分では利用していなくても
例えばgoogle_mobile_adsなどで利用されているため、関連してインストールされてエラーの原因になる。
(表示にflutter_inappwebviewを使っていても、なぜか関連でクラッシュする)

対応方法

エラーの起こらないバージョンをpubspec.yamlで指定して追加

pubspec.yaml
webview_flutter_android: 3.16.1

Androidでapkビルドが成功しない

flutter_inappwebview 6.0.0を利用していると以下のようなエラーが発生

Execution failed for task ':flutter_inappwebview_android:minifyReleaseWithR8'.

対応方法

とりあえず現状だと、以下をpubspec.yamlに追加する形になる。早くアップデートして欲しい

pubspec.yaml
dependency_overrides:
  flutter_inappwebview_android:
    git:
      url: https://github.com/holzgeist/flutter_inappwebview
      path: flutter_inappwebview_android
      ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

参考 : https://github.com/pichillilorenzo/flutter_inappwebview/issues/2193

Discussion