[native assets] Add error message for #169475 (#169866)

Bug:

* https://github.com/flutter/flutter/issues/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.
This commit is contained in:
Daco Harkes 2025-06-02 18:23:37 +02:00 committed by GitHub
parent ead0a01bb9
commit ff2184fc8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -41,6 +41,15 @@ abstract class DartBuild extends Target {
final Uri projectUri = environment.projectDir.uri;
final String? runPackageName =
packageConfig.packages.where((Package p) => p.root == projectUri).firstOrNull?.name;
if (runPackageName == null) {
throw StateError(
'Could not determine run package name. '
'Project path "${projectUri.toFilePath()}" did not occur as package '
'root in package config "${environment.packageConfigPath}". '
'Please report a reproduction on '
'https://github.com/flutter/flutter/issues/169475.',
);
}
final String pubspecPath = packageConfigFile.uri.resolve('../pubspec.yaml').toFilePath();
final FlutterNativeAssetsBuildRunner buildRunner =
_buildRunner ??
@ -49,7 +58,7 @@ abstract class DartBuild extends Target {
packageConfig,
fileSystem,
environment.logger,
runPackageName!,
runPackageName,
pubspecPath,
);
result = await runFlutterSpecificDartBuild(
@ -77,7 +86,7 @@ abstract class DartBuild extends Target {
}
environment.depFileService.writeToFile(depfile, outputDepfile);
if (!await outputDepfile.exists()) {
throwToolExit("${outputDepfile.path} doesn't exist.");
throw StateError("${outputDepfile.path} doesn't exist.");
}
}