Skip to content

Commit ff2184f

Browse files
authored
[native assets] Add error message for #169475 (#169866)
Bug: * flutter/flutter#169475 I don't want to skip building native assets and sweep the actual cause of this under the rug. If native assets would be used, the app build would succeed but accessing the assets would fail at runtime. It seems the project path should always occur as a package root in the package config json. So this is a state error.
1 parent ead0a01 commit ff2184f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

packages/flutter_tools/lib/src/build_system/targets/native_assets.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ abstract class DartBuild extends Target {
4141
final Uri projectUri = environment.projectDir.uri;
4242
final String? runPackageName =
4343
packageConfig.packages.where((Package p) => p.root == projectUri).firstOrNull?.name;
44+
if (runPackageName == null) {
45+
throw StateError(
46+
'Could not determine run package name. '
47+
'Project path "${projectUri.toFilePath()}" did not occur as package '
48+
'root in package config "${environment.packageConfigPath}". '
49+
'Please report a reproduction on '
50+
'https://github.com/flutter/flutter/issues/169475.',
51+
);
52+
}
4453
final String pubspecPath = packageConfigFile.uri.resolve('../pubspec.yaml').toFilePath();
4554
final FlutterNativeAssetsBuildRunner buildRunner =
4655
_buildRunner ??
@@ -49,7 +58,7 @@ abstract class DartBuild extends Target {
4958
packageConfig,
5059
fileSystem,
5160
environment.logger,
52-
runPackageName!,
61+
runPackageName,
5362
pubspecPath,
5463
);
5564
result = await runFlutterSpecificDartBuild(
@@ -77,7 +86,7 @@ abstract class DartBuild extends Target {
7786
}
7887
environment.depFileService.writeToFile(depfile, outputDepfile);
7988
if (!await outputDepfile.exists()) {
80-
throwToolExit("${outputDepfile.path} doesn't exist.");
89+
throw StateError("${outputDepfile.path} doesn't exist.");
8190
}
8291
}
8392

0 commit comments

Comments
 (0)