2
3

FlutterプロジェクトでAGP 8系アップデート時に発生したエラーと対応方法

Posted at

Flutter 3.19.3対応の際、AGP8系にアップデートした際に、直面したエラーとその対応方法を記載します。
同じようなエラーに直面した人の助けになれば幸いです。

前提

僕のアプリでは、以下のライブラリを利用していました。

pubspeck.yaml
environment:
  sdk: '>=3.2.0 <4.0.0'
  flutter: '>=3.19.3'
  
  in_app_review: ^2.0.9
  fcm_config: ^3.5.3
  flutter_local_notifications: ^16.3.2

リリースビルドを作成しようとすると以下のエラーが発生しました

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in */build/app/outputs/mapping/productionRelease/missing_rules.txt.
ERROR: R8: Missing class com.google.android.play.core.splitcompat.SplitCompatApplication (referenced from: void io.flutter.app.FlutterPlayStoreSplitApplication.<init>() and 5 other contexts)
Missing class com.google.android.play.core.splitinstall.SplitInstallException (referenced from: void io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager.lambda$installDeferredComponent$1(int, java.lang.String, java.lang.Exception))

リリースビルド時のR8エラーに関してはGradle / AGP 8系アップデート: 直面したエラーと解決策を参考に以下を追記しました。

app/build.gradle
dependencies {
    implementation 'com.google.android.play:core:1.10.3'
}

しかし、上記を追記することによって新たにライブラリが重複しているというエラーが出ました
これは、in_app_reviewが参照しているcom.google.android.play:review:2.0.1が上記で追加した com.google.android.play:core:1.10.3 と競合しているのが原因でした。

Execution failed for task ':app:checkProductionReleaseDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.google.android.play.core.common.IntentSenderForResultStarter found in modules jetified-core-1.10.0-runtime (com.google.android.play:core:1.10.0) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)
     Duplicate class com.google.android.play.core.common.LocalTestingException found in modules jetified-core-1.10.0-runtime (com.google.android.play:core:1.10.0) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)
     Duplicate class com.google.android.play.core.common.PlayCoreDialogWrapperActivity found in modules jetified-core-1.10.0-runtime (com.google.android.play:core:1.10.0) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)
     Duplicate class com.google.android.play.core.listener.StateUpdatedListener found in modules jetified-core-1.10.0-runtime (com.google.android.play:core:1.10.0) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)

解決方法としてappのbuild.gradleに以下を追記しました。

app/build.gradle
configurations {
    all {
        exclude group: "com.google.android.play", module: "review"
    }
}

com.google.android.play のライブラリからreviewのをexcludeすることで無事にReleaseビルドが作成出来るようになりました。

最後に

走り書きになってしまいましたが、同じ問題に遭遇した方の助けになれば幸いです。

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