39

While trying to build my app in release mode I encountered the following the compiler error:
"This application cannot tree shake icons fonts."

terminal logs:

flutter build ios --release  
Building com.xxx.xxx for device (ios-release)...
Automatically signing iOS for device deployment using specified development team in Xcode project: C7T4CHU88Y
Running Xcode build...                                                  
                                                   
Xcode build done.                                           31.8s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    This application cannot tree shake icons fonts. It has non-constant instances of IconData at the following locations:
      - file:///Users/user-app/lib/screens/categories/subcategories.dart:830:35
      - file:///Users/user-app/lib/screens/home/home.dart:387:17
      - file:///Users/user-app/lib/screens/home/home.dart:399:17
      - file:///Users/user-app/lib/screens/home/home.dart:411:17
      - file:///Users/user-app/lib/screens/home/home.dart:423:17
      - file:///Users/user-app/lib/screens/product/all_products.dart:516:31
      - file:///Users/user-app/lib/screens/tab/saveditems.dart:324:31
      - file:///Users/user-app/lib/screens/tab/searchitem.dart:496:31

The error could result from the following file:

Column(
  children: <Widget>[
    Row(
      children: <Widget>[
        new Text(
          MyLocalizations.of(context).goToCart,
          style: textBarlowRegularBlack(),
        ),
        SizedBox(width: 4),
        Icon(
          IconData(
            0xe911,
            fontFamily: 'icomoon',
          ),
          color: Colors.black,
        ),
      ],
    ),
  ],
),
nocego
  • 15
  • 1
  • 4
iven
  • 401
  • 1
  • 4
  • 6

5 Answers5

67

Try build with --no-tree-shake-icons command.

Anson
  • 905
  • 6
  • 11
14

Add a "const" before the IconData.

Icon(
  const IconData(
    0xe911,
    fontFamily: 'icomoon',
  ),
  color: Colors.black,
),
nocego
  • 15
  • 1
  • 4
Thepeanut
  • 3,074
  • 1
  • 17
  • 23
4

For run

flutter run --release --no-tree-shake-icons

For Android build

flutter build apk --release --no-tree-shake-icons

For iOS build

flutter build ipa --release --no-tree-shake-icons
Anand
  • 4,355
  • 2
  • 35
  • 45
2

For flutter you can export apk with this

flutter build apk --split-per-abi --no-tree-shake-icons
gtr Developer
  • 2,369
  • 16
  • 12
-2

For me also facing same issue in latest version of flutter. So as of now I've downgraded to Channel stable v1.17.5 to skip this tree-shake-icons issue.