Revert "[tool] ⚡️ Install the corresponding APK in flutter run (#112768)" (#113614)

This reverts commit 0ad71e8727.
This commit is contained in:
godofredoc
2022-10-18 10:04:49 -07:00
committed by GitHub
parent 0ad71e8727
commit 4fa91c949a
8 changed files with 46 additions and 81 deletions

View File

@@ -103,20 +103,11 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
required ProcessUtils processUtils,
required Logger logger,
required FileSystem fileSystem,
BuildInfo? buildInfo,
}) async {
final File apkFile;
final String filename;
if (buildInfo == null) {
filename = 'app.apk';
} else if (buildInfo.flavor == null) {
filename = 'app-${buildInfo.mode.name}.apk';
} else {
filename = 'app-${buildInfo.lowerCasedFlavor}-${buildInfo.mode.name}.apk';
}
File apkFile;
if (androidProject.isUsingGradle && androidProject.isSupportedVersion) {
apkFile = getApkDirectory(androidProject.parent).childFile(filename);
apkFile = getApkDirectory(androidProject.parent).childFile('app.apk');
if (apkFile.existsSync()) {
// Grab information from the .apk. The gradle build script might alter
// the application Id, so we need to look at what was actually built.
@@ -133,7 +124,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
// command will grab a new AndroidApk after building, to get the updated
// IDs.
} else {
apkFile = fileSystem.file(fileSystem.path.join(getAndroidBuildDirectory(), filename));
apkFile = fileSystem.file(fileSystem.path.join(getAndroidBuildDirectory(), 'app.apk'));
}
final File manifest = androidProject.appManifestFile;

View File

@@ -465,16 +465,13 @@ class AndroidGradleBuilder implements AndroidBuilder {
);
return;
}
// Gradle produced APKs.
// Gradle produced an APK.
final Iterable<String> apkFilesPaths = project.isModule
? findApkFilesModule(project, androidBuildInfo, _logger, _usage)
: listApkPaths(androidBuildInfo);
final Directory apkDirectory = getApkDirectory(project);
// Copy the first APK to app.apk.
// TODO(AlexV525): Remove the copying once we can identify there are no tools is using the app.apk.
final File firstApkFile = apkDirectory.childFile(apkFilesPaths.first);
if (!firstApkFile.existsSync()) {
final File apkFile = apkDirectory.childFile(apkFilesPaths.first);
if (!apkFile.existsSync()) {
_exitWithExpectedFileNotFound(
project: project,
fileExtension: '.apk',
@@ -482,35 +479,27 @@ class AndroidGradleBuilder implements AndroidBuilder {
usage: _usage,
);
}
firstApkFile.copySync(apkDirectory.childFile('app.apk').path);
// Generate sha1 for every generated APKs.
for (final File apkFile in apkFilesPaths.map(apkDirectory.childFile)) {
if (!apkFile.existsSync()) {
_exitWithExpectedFileNotFound(
project: project,
fileExtension: '.apk',
logger: _logger,
usage: _usage,
);
}
// Copy the first APK to app.apk, so `flutter run` can find it.
// TODO(egarciad): Handle multiple APKs.
apkFile.copySync(apkDirectory
.childFile('app.apk')
.path);
_logger.printTrace('calculateSha: $apkDirectory/app.apk');
final String filename = apkFile.basename;
_logger.printTrace('Calculate SHA1: $apkDirectory/$filename');
final File apkShaFile = apkDirectory.childFile('$filename.sha1');
apkShaFile.writeAsStringSync(_calculateSha(apkFile));
final File apkShaFile = apkDirectory.childFile('app.apk.sha1');
apkShaFile.writeAsStringSync(_calculateSha(apkFile));
final String appSize = (buildInfo.mode == BuildMode.debug)
? '' // Don't display the size when building a debug variant.
: ' (${getSizeAsMB(apkFile.lengthSync())})';
_logger.printStatus(
'${_logger.terminal.successMark} Built ${_fileSystem.path.relative(apkFile.path)}$appSize.',
color: TerminalColor.green,
);
final String appSize = (buildInfo.mode == BuildMode.debug)
? '' // Don't display the size when building a debug variant.
: ' (${getSizeAsMB(apkFile.lengthSync())})';
_logger.printStatus(
'${_logger.terminal.successMark} Built ${_fileSystem.path.relative(apkFile.path)}$appSize.',
color: TerminalColor.green,
);
if (buildInfo.codeSizeDirectory != null) {
await _performCodeSizeAnalysis('apk', apkFile, androidBuildInfo);
}
if (buildInfo.codeSizeDirectory != null) {
await _performCodeSizeAnalysis('apk', apkFile, androidBuildInfo);
}
}