@@ -201,54 +201,19 @@ class BuildApkCommand extends FlutterCommand {
201
201
202
202
@override
203
203
Future <int > runInProject () async {
204
- // Validate that we can find an android sdk.
205
- if (androidSdk == null ) {
206
- printError ('No Android SDK found. Try setting the ANDROID_HOME environment variable.' );
207
- return 1 ;
208
- }
209
-
210
- List <String > validationResult = androidSdk.validateSdkWellFormed ();
211
- if (validationResult.isNotEmpty) {
212
- validationResult.forEach (printError);
213
- printError ('Try re-installing or updating your Android SDK.' );
214
- return 1 ;
215
- }
216
-
217
- BuildMode mode = getBuildMode ();
218
-
219
- Map <String , File > extraFiles = < String , File > {};
220
- for (String addFile in argResults['add-file' ]) {
221
- List <String > keyValue = addFile.split ('=' );
222
- if (keyValue.length != 2 ) {
223
- printError ('add-file option must have the format <path/in/APK>=<local/file/path>' );
224
- return 1 ;
225
- }
226
- extraFiles[keyValue.first] = new File (keyValue.last);
227
- }
228
-
229
- if (FileSystemEntity .isDirectorySync (_kDefaultAssetsPath)) {
230
- Directory assetsDir = new Directory (_kDefaultAssetsPath);
231
- for (FileSystemEntity entity in assetsDir.listSync (recursive: true )) {
232
- if (entity is File ) {
233
- String targetPath = entity.path.substring (assetsDir.path.length);
234
- extraFiles["assets/$targetPath " ] = entity;
235
- }
236
- };
237
- }
238
-
239
204
// TODO(devoncarew): This command should take an arg for the output type (arm / x64).
240
205
241
206
return await buildAndroid (
242
207
TargetPlatform .android_arm,
243
- mode ,
208
+ getBuildMode () ,
244
209
force: true ,
245
210
manifest: argResults['manifest' ],
246
211
resources: argResults['resources' ],
247
212
outputFile: argResults['output-file' ],
248
213
target: argResults['target' ],
249
214
flxPath: argResults['flx' ],
250
215
aotPath: argResults['aot-path' ],
251
- extraFiles : extraFiles ,
216
+ addFiles : argResults[ 'add-file' ] ,
252
217
keystore: (argResults['keystore' ] ?? '' ).isEmpty ? null : new ApkKeystoreInfo (
253
218
keystore: argResults['keystore' ],
254
219
password: argResults['keystore-password' ],
@@ -427,16 +392,19 @@ int _signApk(
427
392
}
428
393
429
394
// Returns true if the apk is out of date and needs to be rebuilt.
430
- bool _needsRebuild (String apkPath, String manifest) {
395
+ bool _needsRebuild (String apkPath, String manifest, Map < String , File > extraFiles ) {
431
396
FileStat apkStat = FileStat .statSync (apkPath);
432
397
// Note: This list of dependencies is imperfect, but will do for now. We
433
398
// purposely don't include the .dart files, because we can load those
434
399
// over the network without needing to rebuild (at least on Android).
435
- Iterable < FileStat > dependenciesStat = < String > [
400
+ List < String > dependencies = < String > [
436
401
manifest,
437
402
_kFlutterManifestPath,
438
403
_kPackagesStatusPath
439
- ].map ((String path) => FileStat .statSync (path));
404
+ ];
405
+ dependencies.addAll (extraFiles.values.map ((File file) => file.path));
406
+ Iterable <FileStat > dependenciesStat =
407
+ dependencies.map ((String path) => FileStat .statSync (path));
440
408
441
409
if (apkStat.type == FileSystemEntityType .NOT_FOUND )
442
410
return true ;
@@ -462,7 +430,7 @@ Future<int> buildAndroid(
462
430
String target,
463
431
String flxPath,
464
432
String aotPath,
465
- Map <String , File > extraFiles ,
433
+ List <String > addFiles ,
466
434
ApkKeystoreInfo keystore
467
435
}) async {
468
436
// Validate that we can find an android sdk.
@@ -478,7 +446,27 @@ Future<int> buildAndroid(
478
446
return 1 ;
479
447
}
480
448
481
- if (! force && ! _needsRebuild (outputFile, manifest)) {
449
+ Map <String , File > extraFiles = < String , File > {};
450
+ for (String addFile in addFiles ?? < String > []) {
451
+ List <String > keyValue = addFile.split ('=' );
452
+ if (keyValue.length != 2 ) {
453
+ printError ('add-file option must have the format <path/in/APK>=<local/file/path>' );
454
+ return 1 ;
455
+ }
456
+ extraFiles[keyValue.first] = new File (keyValue.last);
457
+ }
458
+
459
+ if (FileSystemEntity .isDirectorySync (_kDefaultAssetsPath)) {
460
+ Directory assetsDir = new Directory (_kDefaultAssetsPath);
461
+ for (FileSystemEntity entity in assetsDir.listSync (recursive: true )) {
462
+ if (entity is File ) {
463
+ String targetPath = entity.path.substring (assetsDir.path.length);
464
+ extraFiles["assets/$targetPath " ] = entity;
465
+ }
466
+ };
467
+ }
468
+
469
+ if (! force && ! _needsRebuild (outputFile, manifest, extraFiles)) {
482
470
printTrace ('APK up to date; skipping build step.' );
483
471
return 0 ;
484
472
}
0 commit comments