LoginSignup
4
6

More than 3 years have passed since last update.

Flutter のリリースビルドで app:transformClassesAndResourcesWithProguardForRelease タスクが失敗した場合の対処法

Last updated at Posted at 2019-10-15

環境

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.9.1+hotfix.2, on Mac OS X 10.14.5 18F203, locale ja-JP)

本文

前回の投稿に加えてもうひとつ、 Flutter のリリースビルド時に以下のエラーが出ていてハマったので、その対処法を書いておきます。

エラー内容


$ flutter build appbundle
Initializing gradle...                                              0.7s
Resolving dependencies...                                           1.4s

・・・省略(とてつもなく長いエラー)

Warning: there were 12 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 2 unresolved references to library class members.
         You probably need to update the library versions.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'... Done                         2.5s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
*******************************************************************************************
Gradle task bundleRelease failed with exit code 1

対処法

エラーが長すぎて調査にとても時間がかかってしまったのですが、よく見るとエラーの中に


Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease

と書いてある通り Proguard 関連の処理が原因らしく、 対処法はとてもシンプルに minifyEnabled falseapp/build.gradle に設定して Proguard を無効化することで解決しました。

Flutter と Proguard について

調べてみたら、 Flutter における Proguard の対応は以前から問題が発生していたらしく、以下のような Issue も残っていました。

Android release build crashes with proguard error #25951

しかし↑のような対処だと 「Proguard 無効にしちゃってそれで良いのか」という話になりそうですが、よく考えてみると Proguard の役割は Java / Kotlin コードの難読化と最適化 であって、 Dart コードが大半の Flutter アプリではあまり無理に使う必要がないのでは、ということなのかな、と思っています。

Flutter のドキュメントにも、以下のように「サードパーティーの Java / Kotlin Android ライブラリを使う場合、APKのサイズ削減やリバースエンジニアリングの防止ができます」という旨が書かれていて、

If you intend to use third-party Java, Kotlin, or Android libraries, you might want to reduce the size of the APK or protect that code from reverse engineering

つまり逆に言えばそのような Java / Kotlin 製のライブラリを使っていない場合(特にサイズ圧縮やリバースエンジニアリングされても問題がない場合)は Proguard を使う必要がないとも言えそうです。

もし本当に Dart コードの他に重要な Java / Kotlin コードを含むアプリで上記の問題が発生した場合はまた別の対処法が必要になりそうですが(そしてその方法は未調査ですが)、大半の Flutter 製アプリは「Proguard を無効にする」で良いのではないかと思っています。

4
6
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
4
6