diff --git a/packages/flutter_tools/lib/src/commands/build_apk.dart b/packages/flutter_tools/lib/src/commands/build_apk.dart index 132f2b2ce7d..eadf964dcb0 100644 --- a/packages/flutter_tools/lib/src/commands/build_apk.dart +++ b/packages/flutter_tools/lib/src/commands/build_apk.dart @@ -201,46 +201,11 @@ class BuildApkCommand extends FlutterCommand { @override Future runInProject() async { - // Validate that we can find an android sdk. - if (androidSdk == null) { - printError('No Android SDK found. Try setting the ANDROID_HOME environment variable.'); - return 1; - } - - List validationResult = androidSdk.validateSdkWellFormed(); - if (validationResult.isNotEmpty) { - validationResult.forEach(printError); - printError('Try re-installing or updating your Android SDK.'); - return 1; - } - - BuildMode mode = getBuildMode(); - - Map extraFiles = {}; - for (String addFile in argResults['add-file']) { - List keyValue = addFile.split('='); - if (keyValue.length != 2) { - printError('add-file option must have the format ='); - return 1; - } - extraFiles[keyValue.first] = new File(keyValue.last); - } - - if (FileSystemEntity.isDirectorySync(_kDefaultAssetsPath)) { - Directory assetsDir = new Directory(_kDefaultAssetsPath); - for (FileSystemEntity entity in assetsDir.listSync(recursive: true)) { - if (entity is File) { - String targetPath = entity.path.substring(assetsDir.path.length); - extraFiles["assets/$targetPath"] = entity; - } - }; - } - // TODO(devoncarew): This command should take an arg for the output type (arm / x64). return await buildAndroid( TargetPlatform.android_arm, - mode, + getBuildMode(), force: true, manifest: argResults['manifest'], resources: argResults['resources'], @@ -248,7 +213,7 @@ class BuildApkCommand extends FlutterCommand { target: argResults['target'], flxPath: argResults['flx'], aotPath: argResults['aot-path'], - extraFiles: extraFiles, + addFiles: argResults['add-file'], keystore: (argResults['keystore'] ?? '').isEmpty ? null : new ApkKeystoreInfo( keystore: argResults['keystore'], password: argResults['keystore-password'], @@ -427,16 +392,19 @@ int _signApk( } // Returns true if the apk is out of date and needs to be rebuilt. -bool _needsRebuild(String apkPath, String manifest) { +bool _needsRebuild(String apkPath, String manifest, Map extraFiles) { FileStat apkStat = FileStat.statSync(apkPath); // Note: This list of dependencies is imperfect, but will do for now. We // purposely don't include the .dart files, because we can load those // over the network without needing to rebuild (at least on Android). - Iterable dependenciesStat = [ + List dependencies = [ manifest, _kFlutterManifestPath, _kPackagesStatusPath - ].map((String path) => FileStat.statSync(path)); + ]; + dependencies.addAll(extraFiles.values.map((File file) => file.path)); + Iterable dependenciesStat = + dependencies.map((String path) => FileStat.statSync(path)); if (apkStat.type == FileSystemEntityType.NOT_FOUND) return true; @@ -462,7 +430,7 @@ Future buildAndroid( String target, String flxPath, String aotPath, - Map extraFiles, + List addFiles, ApkKeystoreInfo keystore }) async { // Validate that we can find an android sdk. @@ -478,7 +446,27 @@ Future buildAndroid( return 1; } - if (!force && !_needsRebuild(outputFile, manifest)) { + Map extraFiles = {}; + for (String addFile in addFiles ?? []) { + List keyValue = addFile.split('='); + if (keyValue.length != 2) { + printError('add-file option must have the format ='); + return 1; + } + extraFiles[keyValue.first] = new File(keyValue.last); + } + + if (FileSystemEntity.isDirectorySync(_kDefaultAssetsPath)) { + Directory assetsDir = new Directory(_kDefaultAssetsPath); + for (FileSystemEntity entity in assetsDir.listSync(recursive: true)) { + if (entity is File) { + String targetPath = entity.path.substring(assetsDir.path.length); + extraFiles["assets/$targetPath"] = entity; + } + }; + } + + if (!force && !_needsRebuild(outputFile, manifest, extraFiles)) { printTrace('APK up to date; skipping build step.'); return 0; }