Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This application cannot tree shake icons fonts

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,
        ),
      ],
    ),
  ],
),
like image 414
iven Avatar asked Aug 10 '20 07:08

iven


2 Answers

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

like image 177
Anson Avatar answered Sep 28 '22 05:09

Anson


Add a "const" before the IconData.

Icon(
  const IconData(
    0xe911,
    fontFamily: 'icomoon',
  ),
  color: Colors.black,
),
like image 26
Thepeanut Avatar answered Sep 28 '22 06:09

Thepeanut