mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix #3891 by making flutter run generate identical apks to flutter build apk
This commit is contained in:
parent
3252701753
commit
00e22284f2
@ -201,46 +201,11 @@ class BuildApkCommand extends FlutterCommand {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<int> runInProject() async {
|
Future<int> 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<String> validationResult = androidSdk.validateSdkWellFormed();
|
|
||||||
if (validationResult.isNotEmpty) {
|
|
||||||
validationResult.forEach(printError);
|
|
||||||
printError('Try re-installing or updating your Android SDK.');
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
BuildMode mode = getBuildMode();
|
|
||||||
|
|
||||||
Map<String, File> extraFiles = <String, File>{};
|
|
||||||
for (String addFile in argResults['add-file']) {
|
|
||||||
List<String> keyValue = addFile.split('=');
|
|
||||||
if (keyValue.length != 2) {
|
|
||||||
printError('add-file option must have the format <path/in/APK>=<local/file/path>');
|
|
||||||
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).
|
// TODO(devoncarew): This command should take an arg for the output type (arm / x64).
|
||||||
|
|
||||||
return await buildAndroid(
|
return await buildAndroid(
|
||||||
TargetPlatform.android_arm,
|
TargetPlatform.android_arm,
|
||||||
mode,
|
getBuildMode(),
|
||||||
force: true,
|
force: true,
|
||||||
manifest: argResults['manifest'],
|
manifest: argResults['manifest'],
|
||||||
resources: argResults['resources'],
|
resources: argResults['resources'],
|
||||||
@ -248,7 +213,7 @@ class BuildApkCommand extends FlutterCommand {
|
|||||||
target: argResults['target'],
|
target: argResults['target'],
|
||||||
flxPath: argResults['flx'],
|
flxPath: argResults['flx'],
|
||||||
aotPath: argResults['aot-path'],
|
aotPath: argResults['aot-path'],
|
||||||
extraFiles: extraFiles,
|
addFiles: argResults['add-file'],
|
||||||
keystore: (argResults['keystore'] ?? '').isEmpty ? null : new ApkKeystoreInfo(
|
keystore: (argResults['keystore'] ?? '').isEmpty ? null : new ApkKeystoreInfo(
|
||||||
keystore: argResults['keystore'],
|
keystore: argResults['keystore'],
|
||||||
password: argResults['keystore-password'],
|
password: argResults['keystore-password'],
|
||||||
@ -427,16 +392,19 @@ int _signApk(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the apk is out of date and needs to be rebuilt.
|
// 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<String, File> extraFiles) {
|
||||||
FileStat apkStat = FileStat.statSync(apkPath);
|
FileStat apkStat = FileStat.statSync(apkPath);
|
||||||
// Note: This list of dependencies is imperfect, but will do for now. We
|
// 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
|
// purposely don't include the .dart files, because we can load those
|
||||||
// over the network without needing to rebuild (at least on Android).
|
// over the network without needing to rebuild (at least on Android).
|
||||||
Iterable<FileStat> dependenciesStat = <String>[
|
List<String> dependencies = <String>[
|
||||||
manifest,
|
manifest,
|
||||||
_kFlutterManifestPath,
|
_kFlutterManifestPath,
|
||||||
_kPackagesStatusPath
|
_kPackagesStatusPath
|
||||||
].map((String path) => FileStat.statSync(path));
|
];
|
||||||
|
dependencies.addAll(extraFiles.values.map((File file) => file.path));
|
||||||
|
Iterable<FileStat> dependenciesStat =
|
||||||
|
dependencies.map((String path) => FileStat.statSync(path));
|
||||||
|
|
||||||
if (apkStat.type == FileSystemEntityType.NOT_FOUND)
|
if (apkStat.type == FileSystemEntityType.NOT_FOUND)
|
||||||
return true;
|
return true;
|
||||||
@ -462,7 +430,7 @@ Future<int> buildAndroid(
|
|||||||
String target,
|
String target,
|
||||||
String flxPath,
|
String flxPath,
|
||||||
String aotPath,
|
String aotPath,
|
||||||
Map<String, File> extraFiles,
|
List<String> addFiles,
|
||||||
ApkKeystoreInfo keystore
|
ApkKeystoreInfo keystore
|
||||||
}) async {
|
}) async {
|
||||||
// Validate that we can find an android sdk.
|
// Validate that we can find an android sdk.
|
||||||
@ -478,7 +446,27 @@ Future<int> buildAndroid(
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force && !_needsRebuild(outputFile, manifest)) {
|
Map<String, File> extraFiles = <String, File>{};
|
||||||
|
for (String addFile in addFiles ?? <String>[]) {
|
||||||
|
List<String> keyValue = addFile.split('=');
|
||||||
|
if (keyValue.length != 2) {
|
||||||
|
printError('add-file option must have the format <path/in/APK>=<local/file/path>');
|
||||||
|
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.');
|
printTrace('APK up to date; skipping build step.');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user