@@ -45,7 +45,9 @@ renameApp() async {
45
45
Logger .info ("Let's change all in tests !" );
46
46
await _changeAllImportsIn ("test" , config);
47
47
48
- var shell = Shell ();
48
+ await _changeAndroidPackageName (config);
49
+
50
+ final shell = Shell ();
49
51
50
52
await shell.run ("flutter pub get" );
51
53
} catch (error) {
@@ -56,6 +58,39 @@ renameApp() async {
56
58
}
57
59
}
58
60
61
+ _changeAndroidPackageName (Config config) async {
62
+ Logger .newLine ();
63
+ Logger .info ("Changing android package name" );
64
+ final String newPackageName = config.newAndroidPackageName;
65
+ final List <String > newPackageNameParts = newPackageName.split ("." );
66
+
67
+ final Directory javaDirectory = Directory ("android/app/src/main/java" );
68
+ int index = 0 ;
69
+ javaDirectory.list (recursive: true ).forEach ((FileSystemEntity fileSystemEntity) {
70
+ if (index < newPackageNameParts.length - 1 &&
71
+ fileSystemEntity is Directory &&
72
+ fileSystemEntity.path.endsWith (newPackageNameParts[index])) {
73
+ fileSystemEntity.renameSync (newPackageNameParts[index]);
74
+ print ("CHANGED dir name from ${fileSystemEntity .path } to ${newPackageNameParts [index ]} " );
75
+ index++ ;
76
+ }
77
+ });
78
+
79
+ final Directory kotlinDirectory = Directory ("android/app/src/main/kotlin" );
80
+ index = 0 ;
81
+ kotlinDirectory.list (recursive: true ).forEach ((FileSystemEntity fileSystemEntity) {
82
+ if (index < newPackageNameParts.length - 1 &&
83
+ fileSystemEntity is Directory &&
84
+ fileSystemEntity.path.endsWith (newPackageNameParts[index])) {
85
+ fileSystemEntity.renameSync (newPackageNameParts[index]);
86
+ print ("CHANGED dir name from ${fileSystemEntity .path } to ${newPackageNameParts [index ]} " );
87
+ index++ ;
88
+ }
89
+ });
90
+
91
+ Logger .newLine ();
92
+ }
93
+
59
94
_changeAllImportsIn (String directoryPath, Config config) async {
60
95
final Directory directory = Directory (directoryPath);
61
96
if (directory.existsSync ()) {
@@ -85,7 +120,14 @@ _applyNameChanges(List<RequiredChange> requiredChanges) async {
85
120
_applyContentChanges (List <RequiredChange > requiredChanges) async {
86
121
await Future .forEach (requiredChanges, (RequiredChange change) async {
87
122
for (final path in change.paths) {
88
- await _changeContentInFile (path, change.regexp, change.replacement);
123
+ if (change.isDirectory) {
124
+ final Directory directory = Directory (path);
125
+ Future .forEach (directory.listSync (recursive: true ), (FileSystemEntity entity) async {
126
+ await _changeContentInFile (entity.path, change.regexp, change.replacement);
127
+ });
128
+ } else {
129
+ await _changeContentInFile (path, change.regexp, change.replacement);
130
+ }
89
131
}
90
132
});
91
133
}
@@ -94,7 +136,7 @@ _changeFileName(String filePath, RegExp regexp, String replacement) async {
94
136
if (filePath.contains (regexp)) {
95
137
try {
96
138
final File file = File (filePath);
97
- file.rename (filePath.replaceAll (regexp, replacement));
139
+ file.renameSync (filePath.replaceAll (regexp, replacement));
98
140
} on FileSystemException {
99
141
Logger .error ("File $filePath does not exist on this project" );
100
142
}
0 commit comments