1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Flutter】IconDataでビルドエラー cannot tree shake icons(備忘録)

Last updated at Posted at 2021-03-23

ビルドエラー

$ flutter build apk --release --flavor production --dart-define=FLAVOR=production
Running "flutter pub get" in castlinxmobile...                      3.3s
You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
    To generate an app bundle, run:
        flutter build appbundle --target-platform android-arm,android-arm64,android-x64
        Learn more on: https://developer.android.com/guide/app-bundle
    To split the APKs per ABI, run:
        flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
        Learn more on:  https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split

This application cannot tree shake icons fonts. It has non-constant instances of IconData at the following locations:
  - lib/screen/aaaa/xxxx.dart:624:31
  - lib/screen/aaaa/yyyy.dart:139:35

FAILURE: Build failed with an exception.

原因の箇所

IconData(0xea62, fontFamily: 'MaterialIcons'),

どうやら、IconDataを指定しているのが原因のよう

対処法

オプションに
--no-tree-shake-icons
を指定する

下記実行結果

$ flutter build apk --release --flavor production --dart-define=FLAVOR=production --no-tree-shake-icons

You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
    To generate an app bundle, run:
        flutter build appbundle --target-platform android-arm,android-arm64,android-x64
        Learn more on: https://developer.android.com/guide/app-bundle
    To split the APKs per ABI, run:
        flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
        Learn more on:  https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
注意:/usr/local/bin/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.7.0/android/src/main/java/io/flutter/plugins/firebase/core/FlutterFirebaseCorePlugin.javaは非推奨のAPIを使用またはオーバーライドしています。
注意:詳細は、-Xlint:deprecationオプションを指定して再コンパイルしてください。
注意:/usr/local/bin/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_analytics-7.0.1/android/src/main/java/io/flutter/plugins/firebaseanalytics/FirebaseAnalyticsPlugin.javaは非推奨のAPIを使用またはオーバーライドしています。
注意:詳細は、-Xlint:deprecationオプションを指定して再コンパイルしてください。
Running Gradle task 'assembleProductionRelease'...
Removed unused resources: Binary resource data reduced from 802KB to 802KB: Removed 0%
Running Gradle task 'assembleProductionRelease'...
Running Gradle task 'assembleProductionRelease'... Done           183.8s (!)
✓ Built build/app/outputs/flutter-apk/app-production-release.apk (69.3MB).

参考記事

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?