findNativeLibInPackageConfig function
Last-resort lookup of lib/native/<platform>/<libName> inside package,
by reading .dart_tool/package_config.json directly (searching upward
from startDir, default the current directory).
Isolate.resolvePackageUriSync throws UnsupportedError under
flutter test (Flutter 3.47+), so the package: URI strategy cannot find
a library that dart run <package>:<build tool> copied into the package.
Reads local files only, so it is safe for offline builds.
Implementation
String? findNativeLibInPackageConfig({
required String package,
required String platform,
required String libName,
Directory? startDir,
}) {
var dir = startDir ?? Directory.current;
while (true) {
final config = File(p.join(dir.path, '.dart_tool', 'package_config.json'));
if (config.existsSync()) {
final path = _libFromConfig(config, package, platform, libName);
if (path != null) return path;
}
final parent = dir.parent;
if (parent.path == dir.path) return null;
dir = parent;
}
}