From 1d13985b91250d5f239c4e2a267ddb6a010c9a3b Mon Sep 17 00:00:00 2001 From: Malvin Pratama Putra Date: Tue, 26 Aug 2025 23:16:52 +0700 Subject: [PATCH 1/8] Feat: - Add support for custom_dir_path on melos --- lib/constants.dart | 1 + lib/platforms/android.dart | 44 ++++++++++++++++++++++++++++++-------- lib/platforms/ios.dart | 28 ++++++++++++++++-------- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index 641d0bb..01945a0 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -46,6 +46,7 @@ const _copyrightKey = 'copyright_notice'; const _languageKey = 'lang'; const _executableKey = 'exe_name'; const _overrideOldPackageKey = 'override_old_package'; +const _customDirPath = 'custom_dir_path'; // ! Directory Paths // ? Android diff --git a/lib/platforms/android.dart b/lib/platforms/android.dart index 4cb01ca..80f2c79 100644 --- a/lib/platforms/android.dart +++ b/lib/platforms/android.dart @@ -28,12 +28,18 @@ void _setAndroidConfigurations(dynamic androidConfig) { } } -void _setAndroidAppName(dynamic appName) { +void _setAndroidAppName(dynamic appName, String? customDirPath) { try { if (appName == null) return; if (appName is! String) throw _PackageRenameErrors.invalidAppName; - final androidManifestFile = File(_androidMainManifestFilePath); + final androidMainManifestFilePath = + (customDirPath is String && customDirPath.isNotEmpty) + ? _androidMainManifestFilePath.replaceAll( + _androidAppDirPath, customDirPath) + : _androidMainManifestFilePath; + + final androidManifestFile = File(androidMainManifestFilePath); if (!androidManifestFile.existsSync()) { throw _PackageRenameErrors.androidMainManifestNotFound; } @@ -61,15 +67,24 @@ void _setAndroidAppName(dynamic appName) { } } -void _setAndroidPackageName(dynamic packageName) { +void _setAndroidPackageName(dynamic packageName, String? customDirPath) { try { if (packageName == null) return; if (packageName is! String) throw _PackageRenameErrors.invalidPackageName; final androidManifestFilePaths = [ - _androidMainManifestFilePath, - _androidDebugManifestFilePath, - _androidProfileManifestFilePath, + (customDirPath is String && customDirPath.isNotEmpty) + ? _androidMainManifestFilePath.replaceAll( + _androidAppDirPath, customDirPath) + : _androidMainManifestFilePath, + (customDirPath is String && customDirPath.isNotEmpty) + ? _androidDebugManifestFilePath.replaceAll( + _androidAppDirPath, customDirPath) + : _androidDebugManifestFilePath, + (customDirPath is String && customDirPath.isNotEmpty) + ? _androidProfileManifestFilePath.replaceAll( + _androidAppDirPath, customDirPath) + : _androidProfileManifestFilePath, ]; _setManifestPackageName( @@ -78,8 +93,15 @@ void _setAndroidPackageName(dynamic packageName) { ); _setBuildGradlePackageName( - buildGradleFilePath: _androidAppLevelBuildGradleFilePath, - kotlinBuildGradleFilePath: _androidAppLevelKotlinBuildGradleFilePath, + buildGradleFilePath: (customDirPath is String && customDirPath.isNotEmpty) + ? _androidAppLevelBuildGradleFilePath.replaceAll( + _androidAppDirPath, customDirPath) + : _androidAppLevelBuildGradleFilePath, + kotlinBuildGradleFilePath: + (customDirPath is String && customDirPath.isNotEmpty) + ? _androidAppLevelKotlinBuildGradleFilePath.replaceAll( + _androidAppDirPath, customDirPath) + : _androidAppLevelKotlinBuildGradleFilePath, packageName: packageName, ); } on _PackageRenameException catch (e) { @@ -183,6 +205,7 @@ void _createNewMainActivity({ required dynamic lang, required dynamic packageName, required dynamic overrideOldPackage, + String? customDirPath, }) { try { if (packageName == null) return; @@ -205,7 +228,10 @@ void _createNewMainActivity({ if (overrideOldPackage == null) { final packageDirs = packageName.replaceAll('.', '/'); - final langDir = '$_androidMainDirPath/$lang'; + final dirPath = (customDirPath is String && customDirPath.isNotEmpty) + ? '${_androidMainDirPath.replaceAll(_androidAppDirPath, customDirPath)}/$lang' + : '$_androidMainDirPath/$lang'; + final langDir = dirPath; final mainActivityFile = File( '$langDir/$packageDirs/MainActivity.$fileExtension', diff --git a/lib/platforms/ios.dart b/lib/platforms/ios.dart index 1914109..b95438d 100644 --- a/lib/platforms/ios.dart +++ b/lib/platforms/ios.dart @@ -6,10 +6,11 @@ void _setIOSConfigurations(dynamic iosConfig) { if (iosConfig is! Map) throw _PackageRenameErrors.invalidIOSConfig; final iosConfigMap = Map.from(iosConfig); + final customDirPath = iosConfigMap[_customDirPath]; - _setIOSDisplayName(iosConfigMap[_appNameKey]); - _setIOSBundleName(iosConfigMap[_bundleNameKey]); - _setIOSPackageName(iosConfigMap[_packageNameKey]); + _setIOSDisplayName(iosConfigMap[_appNameKey], customDirPath: customDirPath); + _setIOSBundleName(iosConfigMap[_bundleNameKey], customDirPath: customDirPath); + _setIOSPackageName(iosConfigMap[_packageNameKey], customDirPath: customDirPath); } on _PackageRenameException catch (e) { _logger ..e('${e.message}ERR Code: ${e.code}') @@ -24,12 +25,15 @@ void _setIOSConfigurations(dynamic iosConfig) { } } -void _setIOSDisplayName(dynamic appName) { +void _setIOSDisplayName(dynamic appName, {String? customDirPath}) { try { if (appName == null) return; if (appName is! String) throw _PackageRenameErrors.invalidAppName; - final iosInfoPlistFile = File(_iosInfoPlistFilePath); + final iosInfoPlistFilePath = (customDirPath is String && customDirPath.isNotEmpty) + ? _iosInfoPlistFilePath.replaceFirst(_iosDirPath, customDirPath) + : _iosInfoPlistFilePath; + final iosInfoPlistFile = File(iosInfoPlistFilePath); if (!iosInfoPlistFile.existsSync()) { throw _PackageRenameErrors.iosInfoPlistNotFound; } @@ -57,7 +61,7 @@ void _setIOSDisplayName(dynamic appName) { } } -void _setIOSBundleName(dynamic bundleName) { +void _setIOSBundleName(dynamic bundleName, {String? customDirPath}) { try { if (bundleName == null) return; if (bundleName is! String) throw _PackageRenameErrors.invalidBundleName; @@ -68,7 +72,10 @@ void _setIOSBundleName(dynamic bundleName) { ); } - final iosInfoPlistFile = File(_iosInfoPlistFilePath); + final iosInfoPlistFilePath = (customDirPath is String && customDirPath.isNotEmpty) + ? _iosInfoPlistFilePath.replaceFirst(_iosDirPath, customDirPath) + : _iosInfoPlistFilePath; + final iosInfoPlistFile = File(iosInfoPlistFilePath); if (!iosInfoPlistFile.existsSync()) { throw _PackageRenameErrors.iosInfoPlistNotFound; } @@ -96,12 +103,15 @@ void _setIOSBundleName(dynamic bundleName) { } } -void _setIOSPackageName(dynamic packageName) { +void _setIOSPackageName(dynamic packageName, {String? customDirPath}) { try { if (packageName == null) return; if (packageName is! String) throw _PackageRenameErrors.invalidPackageName; - final iosProjectFile = File(_iosProjectFilePath); + final iosProjectFilePath = (customDirPath is String && customDirPath.isNotEmpty) + ? _iosProjectFilePath.replaceFirst(_iosDirPath, customDirPath) + : _iosProjectFilePath; + final iosProjectFile = File(iosProjectFilePath); if (!iosProjectFile.existsSync()) { throw _PackageRenameErrors.iosProjectFileNotFound; } From c1ce4b9b2eaccdb6b064ffab4f2f951b63cea871 Mon Sep 17 00:00:00 2001 From: Malvin Pratama Putra Date: Sun, 31 Aug 2025 08:53:33 +0700 Subject: [PATCH 2/8] feat(android): enhance configuration handling with custom directory path --- lib/platforms/android.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/platforms/android.dart b/lib/platforms/android.dart index 80f2c79..4ea6578 100644 --- a/lib/platforms/android.dart +++ b/lib/platforms/android.dart @@ -2,17 +2,21 @@ part of '../package_rename.dart'; void _setAndroidConfigurations(dynamic androidConfig) { try { + _logger.i('Custom dir path: $androidConfig'); if (androidConfig == null) return; if (androidConfig is! Map) throw _PackageRenameErrors.invalidAndroidConfig; final androidConfigMap = Map.from(androidConfig); - _setAndroidAppName(androidConfigMap[_appNameKey]); - _setAndroidPackageName(androidConfigMap[_packageNameKey]); + _setAndroidAppName( + androidConfigMap[_appNameKey], androidConfigMap[_customDirPath]); + _setAndroidPackageName( + androidConfigMap[_packageNameKey], androidConfigMap[_customDirPath]); _createNewMainActivity( lang: androidConfigMap[_languageKey], packageName: androidConfigMap[_packageNameKey], overrideOldPackage: androidConfigMap[_overrideOldPackageKey], + customDirPath: androidConfigMap[_customDirPath], ); } on _PackageRenameException catch (e) { _logger From a0e6263195345891ee944629e74b5f66fc19cf01 Mon Sep 17 00:00:00 2001 From: Malvin Pratama Putra Date: Sun, 31 Aug 2025 08:55:09 +0700 Subject: [PATCH 3/8] feat(android): remove logging of custom directory path in configuration --- lib/platforms/android.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/platforms/android.dart b/lib/platforms/android.dart index 4ea6578..1d349f8 100644 --- a/lib/platforms/android.dart +++ b/lib/platforms/android.dart @@ -2,7 +2,6 @@ part of '../package_rename.dart'; void _setAndroidConfigurations(dynamic androidConfig) { try { - _logger.i('Custom dir path: $androidConfig'); if (androidConfig == null) return; if (androidConfig is! Map) throw _PackageRenameErrors.invalidAndroidConfig; From 3477c32ee3c63244b2073b1361fb4a3341063717 Mon Sep 17 00:00:00 2001 From: malvinpratamaputra Date: Tue, 16 Sep 2025 16:08:23 +0700 Subject: [PATCH 4/8] Update constants.dart --- lib/constants.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index 01945a0..151248d 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -129,9 +129,9 @@ final _majorTaskDoneLine = '━' * _outputLength; const _androidKotlinMainActivityTemplate = ''' package {{packageName}} -import io.flutter.embedding.android.FlutterActivity +import io.flutter.embedding.android.FlutterFragmentActivity -class MainActivity : FlutterActivity() +class MainActivity : FlutterFragmentActivity() '''; const _androidJavaMainActivityTemplate = ''' From a6273f7a4d41d9bb05346f1846123c62543140b4 Mon Sep 17 00:00:00 2001 From: Malvin Pratama Putra Date: Fri, 7 Nov 2025 15:13:47 +0700 Subject: [PATCH 5/8] feat(android): add host parameter to Android app name configuration --- lib/constants.dart | 1 + lib/platforms/android.dart | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index 151248d..daf5602 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -47,6 +47,7 @@ const _languageKey = 'lang'; const _executableKey = 'exe_name'; const _overrideOldPackageKey = 'override_old_package'; const _customDirPath = 'custom_dir_path'; +const _host = 'host'; // ! Directory Paths // ? Android diff --git a/lib/platforms/android.dart b/lib/platforms/android.dart index 1d349f8..969cd85 100644 --- a/lib/platforms/android.dart +++ b/lib/platforms/android.dart @@ -8,7 +8,7 @@ void _setAndroidConfigurations(dynamic androidConfig) { final androidConfigMap = Map.from(androidConfig); _setAndroidAppName( - androidConfigMap[_appNameKey], androidConfigMap[_customDirPath]); + androidConfigMap[_appNameKey], androidConfigMap[_customDirPath], androidConfigMap[_host]); _setAndroidPackageName( androidConfigMap[_packageNameKey], androidConfigMap[_customDirPath]); _createNewMainActivity( @@ -31,7 +31,7 @@ void _setAndroidConfigurations(dynamic androidConfig) { } } -void _setAndroidAppName(dynamic appName, String? customDirPath) { +void _setAndroidAppName(dynamic appName, String? customDirPath, dynamic host) { try { if (appName == null) return; if (appName is! String) throw _PackageRenameErrors.invalidAppName; @@ -48,10 +48,16 @@ void _setAndroidAppName(dynamic appName, String? customDirPath) { } final androidManifestString = androidManifestFile.readAsStringSync(); - final newLabelAndroidManifestString = androidManifestString.replaceAll( + String newLabelAndroidManifestString = androidManifestString.replaceAll( RegExp('android:label="(.*)"'), 'android:label="$appName"', ); + if (host is String && host.isNotEmpty) { + newLabelAndroidManifestString = newLabelAndroidManifestString.replaceAll( + RegExp('android:host="(.*)"'), + 'android:host="$appName"', + ); + } androidManifestFile.writeAsStringSync(newLabelAndroidManifestString); From bf6d3b8d1ba14fad73f714916c6dcfb4661239f3 Mon Sep 17 00:00:00 2001 From: Malvin Pratama Putra Date: Fri, 7 Nov 2025 15:17:59 +0700 Subject: [PATCH 6/8] feat(android): update Android host in AndroidManifest.xml configuration --- lib/platforms/android.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/platforms/android.dart b/lib/platforms/android.dart index 969cd85..8a0dbdb 100644 --- a/lib/platforms/android.dart +++ b/lib/platforms/android.dart @@ -55,8 +55,9 @@ void _setAndroidAppName(dynamic appName, String? customDirPath, dynamic host) { if (host is String && host.isNotEmpty) { newLabelAndroidManifestString = newLabelAndroidManifestString.replaceAll( RegExp('android:host="(.*)"'), - 'android:host="$appName"', + 'android:host="$host"', ); + _logger.i('Android Host set to: `$host` (main AndroidManifest.xml)'); } androidManifestFile.writeAsStringSync(newLabelAndroidManifestString); From 0e5d75504adc406c9aefbaa620f517683d1763c2 Mon Sep 17 00:00:00 2001 From: Malvin Pratama Putra Date: Fri, 7 Nov 2025 17:10:55 +0700 Subject: [PATCH 7/8] feat(android): update directory path handling in _createNewMainActivity --- lib/platforms/android.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/platforms/android.dart b/lib/platforms/android.dart index 8a0dbdb..d72b92e 100644 --- a/lib/platforms/android.dart +++ b/lib/platforms/android.dart @@ -276,7 +276,10 @@ void _createNewMainActivity({ // to new package directory structure final oldPackageDirs = overrideOldPackage.replaceAll('.', '/'); final newPackageDirs = packageName.replaceAll('.', '/'); - final langDir = '$_androidMainDirPath/$lang'; + final dirPath = (customDirPath is String && customDirPath.isNotEmpty) + ? '${_androidMainDirPath.replaceAll(_androidAppDirPath, customDirPath)}/$lang' + : '$_androidMainDirPath/$lang'; + final langDir = dirPath; final oldMainActivityDir = Directory('$langDir/$oldPackageDirs'); if (!oldMainActivityDir.existsSync()) { From b57715228c512856c7656691e283b88eecaeca73 Mon Sep 17 00:00:00 2001 From: Malvin Pratama Putra Date: Sat, 8 Nov 2025 08:02:00 +0700 Subject: [PATCH 8/8] feat(android): enhance logging for MainActivity creation and package movement --- lib/platforms/android.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/platforms/android.dart b/lib/platforms/android.dart index d72b92e..578553c 100644 --- a/lib/platforms/android.dart +++ b/lib/platforms/android.dart @@ -333,7 +333,20 @@ void _createNewMainActivity({ } } - _logger.i('New MainActivity.${lang == 'kotlin' ? 'kt' : 'java'} created'); + if (overrideOldPackage == null) { + _logger.i( + 'New MainActivity.${lang == 'kotlin' ? 'kt' : 'java'} created at: ' + '${(customDirPath is String && customDirPath.isNotEmpty) ? customDirPath : _androidAppDirPath}/' + 'src/main/$lang/${packageName.replaceAll('.', '/')}', + ); + } else { + _logger.i( + 'MainActivity.${lang == 'kotlin' ? 'kt' : 'java'} moved from package: ' + '`$overrideOldPackage` to `$packageName` at: ' + '${(customDirPath is String && customDirPath.isNotEmpty) ? customDirPath : _androidAppDirPath}/' + 'src/main/$lang/${packageName.replaceAll('.', '/')}', + ); + } } on _PackageRenameException catch (e) { _logger ..e('${e.message}ERR Code: ${e.code}')