writeAppIdFromProjectForLaunch function
Reads the app bundle id (iOS/macOS) or application id (Android) from the project's native config files and persists it to appIdFile.
Silently no-ops on any failure — crash-report falls back to --app-id flag.
Implementation
void writeAppIdFromProjectForLaunch(String projectPath) {
try {
final platformInfo = readPlatformInfo();
final platform = platformInfo?.platform ?? '';
final isIos = platform.startsWith('ios');
final isMacos = platform == 'macos' || platform.startsWith('darwin');
final hasPlatformHint = isIos || isMacos || platform.startsWith('android');
if (!hasPlatformHint) {
final candidates = {
...[
_readIosAppId(projectPath),
_readMacosAppId(projectPath),
_readAndroidAppId(projectPath),
].whereType<String>(),
};
if (candidates.length == 1) {
writeAppId(candidates.single);
}
return;
}
final extractors = <String? Function()>[
if (isIos) () => _readIosAppId(projectPath),
if (isMacos) () => _readMacosAppId(projectPath),
if (!isIos && !isMacos) () => _readAndroidAppId(projectPath),
if (!isIos) () => _readIosAppId(projectPath),
if (!isMacos) () => _readMacosAppId(projectPath),
];
for (final extractor in extractors) {
final id = extractor();
if (id != null) {
writeAppId(id);
return;
}
}
} catch (_) {
// Non-fatal: crash-report will prompt for --app-id.
}
}