Repository navigation
IconTreeShakerException: Invalid ConstFinder result #147189
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: buildBuilding flutter applications with the toolBuilding flutter applications with the toolhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool teamwaiting for PR to land (fixed)A fix is in flightA fix is in flight
Description
Working on a new widget in the widgets layer, I defined a const Icon using the ascii value for the IconData:
const Icon(IconData(0x25BA));Since the Icon widget is defined in the widgets layer, I thought this should work fine. Running an app with this builds and works fine.
When I pushed a PR, CI was very unhappy. This use of Icon results in an error from the IconTreeShaker.
flutter build apk --release
Target aot_android_asset_bundle failed: IconTreeShakerException: Invalid ConstFinder result. Expected "fontPackage" to be a String, "fontFamily" to be a String, and "codePoint" to be an int, got: {codePoint: 9658, fontFamily: null, fontPackage: null, matchTextDirection: false, fontFamilyFallback: null}.
To disable icon tree shaking, pass --no-tree-shake-icons to the requested flutter build command
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command '/Users/katelovett/_github/flutter/bin/flutter'' finished with non-zero exit value 1
* 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 14s
Running Gradle task 'assembleRelease'... 14.7s
Gradle task assembleRelease failed with exit code 1
I figured I was holding it wrong and was not allowed to do this, but @goderbauer suspects this is a bug in the icon tree shaker script.
This can be reproduced with the following code and the command flutter build apk --release
import 'package:flutter/material.dart';
void main() => runApp(const SliverTreeExampleApp());
class SliverTreeExampleApp extends StatelessWidget {
const SliverTreeExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: SliverTreeExample(),
);
}
}
class SliverTreeExample extends StatelessWidget {
const SliverTreeExample({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(child: Icon(IconData(0x25BA)),),
);
}
}
This is an example build where I saw this in CI: https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20build_tests_2_3/33418/overview
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: buildBuilding flutter applications with the toolBuilding flutter applications with the toolhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool teamwaiting for PR to land (fixed)A fix is in flightA fix is in flight
Activity
jonahwilliams commentedon Apr 22, 2024
I actually think this is WAI. Without any font information associated with that Icon there is no way for icon tree shaker to work without retaining that codepoint for any possible icon font. You should provide the fontFamily/fontPackage that the code point is expected to be from.
Piinks commentedon Apr 22, 2024
At first I thought we just couldn't do this in the framework from the widgets layer. Is there a built in fontFamily/fontPackage I can point to at that layer?
Piinks commentedon Apr 22, 2024
Or maybe better question, when I run it in debug mode and it works alright, what fontFamily/fontPackage is it using by default?
jonahwilliams commentedon Apr 22, 2024
The icon tree shake doesn't run in debug mode. Which Icon are you trying to refer to? If its a Material Icon you need to specify
fontFamily: 'MaterialIcons'If you don't specify a font then you'll get whatever random glyph happens to be in the first font the OS font manager selects, which is probably going to be a tofu character.
Piinks commentedon Apr 22, 2024
Yeah, and it works as expected..
I'm just using a little arrow icon, 0x25BA. I am trying to avoid material because I am in the widgets layer.
Looking at the code, the Icon itself just boils down to a TextSpan and does not require a font family or font package. Can it not just fallback like regular text? That is what happens in debug, and I get the arrow I expect.
jonahwilliams commentedon Apr 22, 2024
Whether or not you add the
MaterialIconsstring to the IconData, you're depending on the material icons font being present. If you don't specify that, you're relying on the fact that the material icons font is present and is the only font with a 0x25BA code point.Piinks commentedon Apr 22, 2024
Oh interesting. I didn't take the value from material icons, it's just unicode. https://unicodes.jessetane.com/%E2%96%BA
This feels odd, that an Icon will use same fallback font Flutter uses for text (Roboto), but the tree shaker does not allow it.
I don't think it is using the material icons font, I have specifically excluded anything material.
jonahwilliams commentedon Apr 22, 2024
Oh I C! So essentially you want whatever is on the system. You could try specifying a font, but maybe the right solution is some kind of tree shaker opt out?
goderbauer commentedon Apr 22, 2024
This is what I was thinking when discussing this with Kate. It's supposed to use a system font that isn't bundled with the app so the tree shaker should just ... let it be.
jonahwilliams commentedon Apr 22, 2024
We could make the script ignore IconData without a fontFamil or fontPackage.
Piinks commentedon Apr 22, 2024
Happy to send a PR, wasn't sure if that would pass the sniff test!
Update icon tree shaker to allow system font fallback (#147202)
github-actions commentedon May 7, 2024
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.