run method
运行 Android 工程的替换任务
Implementation
Future<void> run({required String dirPath, required FarConfig farConfig}) async {
currentDirPath = dirPath;
if (farConfig.enable == false) {
logSkipping("$platform settings enable is false");
return;
}
final newName = farConfig.appName ?? '';
final package = farConfig.package ?? '';
if (newName.isEmpty) {
log("Android app name is empty.");
return;
}
// final stringsXmlFile = File(
// '$currentDirPath/android/app/src/main/res/values/strings.xml',
// );
// if (!stringsXmlFile.existsSync()) {
// log(text: "FARPlatformAndroid: strings.xml does not exist at ${stringsXmlFile.path}");
// return;
// }
// AndroidManifest.xml
try {
final manifest = FARPlatformAndroidManifest(currentDirPath, newName, package);
await manifest.update();
log("Android AndroidManifest.xml name updated!");
} catch (e) {
log("Android failed to update app_name, e: $e");
}
try {
processBuildGradleBundleId(bundleId: package);
} catch (e) {
log("Android failed to update app/build.gradle bundleId, e: $e");
}
try {
if (package.isNotEmpty) {
log("Android start process rename bundle id dir --- code dirs and files...");
await processAndroidCodeFileDirectory(currentDirPath: currentDirPath, newPackage: package);
log("Android process rename bundle id dir --- code dirs and files completed!");
} else {
log("Android process rename bundle id dir --- no need to rename dir, new package name: $package");
}
} catch (e) {
log("Android process rename bundle id dir --- error:$e");
}
log("Android -> name update completed. ✅");
}