Skip to content

Commit 4fa91c9

Browse files
authored
Revert "[tool] ⚡️ Install the corresponding APK in flutter run (#112768)" (#113614)
This reverts commit 0ad71e8.
1 parent 0ad71e8 commit 4fa91c9

8 files changed

+47
-82
lines changed

packages/flutter_tools/lib/src/android/application_package.dart

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,11 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
103103
required ProcessUtils processUtils,
104104
required Logger logger,
105105
required FileSystem fileSystem,
106-
BuildInfo? buildInfo,
107106
}) async {
108-
final File apkFile;
109-
final String filename;
110-
if (buildInfo == null) {
111-
filename = 'app.apk';
112-
} else if (buildInfo.flavor == null) {
113-
filename = 'app-${buildInfo.mode.name}.apk';
114-
} else {
115-
filename = 'app-${buildInfo.lowerCasedFlavor}-${buildInfo.mode.name}.apk';
116-
}
107+
File apkFile;
117108

118109
if (androidProject.isUsingGradle && androidProject.isSupportedVersion) {
119-
apkFile = getApkDirectory(androidProject.parent).childFile(filename);
110+
apkFile = getApkDirectory(androidProject.parent).childFile('app.apk');
120111
if (apkFile.existsSync()) {
121112
// Grab information from the .apk. The gradle build script might alter
122113
// the application Id, so we need to look at what was actually built.
@@ -133,7 +124,7 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
133124
// command will grab a new AndroidApk after building, to get the updated
134125
// IDs.
135126
} else {
136-
apkFile = fileSystem.file(fileSystem.path.join(getAndroidBuildDirectory(), filename));
127+
apkFile = fileSystem.file(fileSystem.path.join(getAndroidBuildDirectory(), 'app.apk'));
137128
}
138129

139130
final File manifest = androidProject.appManifestFile;

packages/flutter_tools/lib/src/android/gradle.dart

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -465,52 +465,41 @@ class AndroidGradleBuilder implements AndroidBuilder {
465465
);
466466
return;
467467
}
468-
// Gradle produced APKs.
468+
// Gradle produced an APK.
469469
final Iterable<String> apkFilesPaths = project.isModule
470470
? findApkFilesModule(project, androidBuildInfo, _logger, _usage)
471471
: listApkPaths(androidBuildInfo);
472472
final Directory apkDirectory = getApkDirectory(project);
473-
474-
// Copy the first APK to app.apk.
475-
// TODO(AlexV525): Remove the copying once we can identify there are no tools is using the app.apk.
476-
final File firstApkFile = apkDirectory.childFile(apkFilesPaths.first);
477-
if (!firstApkFile.existsSync()) {
473+
final File apkFile = apkDirectory.childFile(apkFilesPaths.first);
474+
if (!apkFile.existsSync()) {
478475
_exitWithExpectedFileNotFound(
479476
project: project,
480477
fileExtension: '.apk',
481478
logger: _logger,
482479
usage: _usage,
483480
);
484481
}
485-
firstApkFile.copySync(apkDirectory.childFile('app.apk').path);
486-
487-
// Generate sha1 for every generated APKs.
488-
for (final File apkFile in apkFilesPaths.map(apkDirectory.childFile)) {
489-
if (!apkFile.existsSync()) {
490-
_exitWithExpectedFileNotFound(
491-
project: project,
492-
fileExtension: '.apk',
493-
logger: _logger,
494-
usage: _usage,
495-
);
496-
}
497482

498-
final String filename = apkFile.basename;
499-
_logger.printTrace('Calculate SHA1: $apkDirectory/$filename');
500-
final File apkShaFile = apkDirectory.childFile('$filename.sha1');
501-
apkShaFile.writeAsStringSync(_calculateSha(apkFile));
483+
// Copy the first APK to app.apk, so `flutter run` can find it.
484+
// TODO(egarciad): Handle multiple APKs.
485+
apkFile.copySync(apkDirectory
486+
.childFile('app.apk')
487+
.path);
488+
_logger.printTrace('calculateSha: $apkDirectory/app.apk');
502489

503-
final String appSize = (buildInfo.mode == BuildMode.debug)
504-
? '' // Don't display the size when building a debug variant.
505-
: ' (${getSizeAsMB(apkFile.lengthSync())})';
506-
_logger.printStatus(
507-
'${_logger.terminal.successMark} Built ${_fileSystem.path.relative(apkFile.path)}$appSize.',
508-
color: TerminalColor.green,
509-
);
490+
final File apkShaFile = apkDirectory.childFile('app.apk.sha1');
491+
apkShaFile.writeAsStringSync(_calculateSha(apkFile));
510492

511-
if (buildInfo.codeSizeDirectory != null) {
512-
await _performCodeSizeAnalysis('apk', apkFile, androidBuildInfo);
513-
}
493+
final String appSize = (buildInfo.mode == BuildMode.debug)
494+
? '' // Don't display the size when building a debug variant.
495+
: ' (${getSizeAsMB(apkFile.lengthSync())})';
496+
_logger.printStatus(
497+
'${_logger.terminal.successMark} Built ${_fileSystem.path.relative(apkFile.path)}$appSize.',
498+
color: TerminalColor.green,
499+
);
500+
501+
if (buildInfo.codeSizeDirectory != null) {
502+
await _performCodeSizeAnalysis('apk', apkFile, androidBuildInfo);
514503
}
515504
}
516505

packages/flutter_tools/lib/src/flutter_application_package.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory {
6666
androidSdk: _androidSdk,
6767
userMessages: _userMessages,
6868
fileSystem: _fileSystem,
69-
buildInfo: buildInfo,
7069
);
7170
}
7271
return AndroidApk.fromApk(

packages/flutter_tools/test/general.shard/android/android_device_start_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void main() {
6565
platform: FakePlatform(),
6666
androidSdk: androidSdk,
6767
);
68-
final File apkFile = fileSystem.file('app-debug.apk')..createSync();
68+
final File apkFile = fileSystem.file('app.apk')..createSync();
6969
final AndroidApk apk = AndroidApk(
7070
id: 'FlutterApp',
7171
applicationPackage: apkFile,
@@ -88,7 +88,7 @@ void main() {
8888
command: <String>['adb', '-s', '1234', 'shell', 'pm', 'list', 'packages', 'FlutterApp'],
8989
));
9090
processManager.addCommand(const FakeCommand(
91-
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', 'app-debug.apk'],
91+
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', 'app.apk'],
9292
));
9393
processManager.addCommand(kShaCommand);
9494
processManager.addCommand(const FakeCommand(
@@ -132,7 +132,7 @@ void main() {
132132
platform: FakePlatform(),
133133
androidSdk: androidSdk,
134134
);
135-
final File apkFile = fileSystem.file('app-debug.apk')..createSync();
135+
final File apkFile = fileSystem.file('app.apk')..createSync();
136136
final AndroidApk apk = AndroidApk(
137137
id: 'FlutterApp',
138138
applicationPackage: apkFile,
@@ -170,7 +170,7 @@ void main() {
170170
platform: FakePlatform(),
171171
androidSdk: androidSdk,
172172
);
173-
final File apkFile = fileSystem.file('app-debug.apk')..createSync();
173+
final File apkFile = fileSystem.file('app.apk')..createSync();
174174
final AndroidApk apk = AndroidApk(
175175
id: 'FlutterApp',
176176
applicationPackage: apkFile,
@@ -200,7 +200,7 @@ void main() {
200200
'-r',
201201
'--user',
202202
'10',
203-
'app-debug.apk',
203+
'app.apk',
204204
],
205205
stdout: '\n\nThe Dart VM service is listening on http://127.0.0.1:456\n\n',
206206
));

packages/flutter_tools/test/general.shard/android/android_install_test.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const FakeCommand kInstallCommand = FakeCommand(
3131
'-r',
3232
'--user',
3333
'10',
34-
'app-debug.apk',
34+
'app.apk',
3535
],
3636
);
3737
const FakeCommand kStoreShaCommand = FakeCommand(
@@ -71,7 +71,7 @@ void main() {
7171
stdout: '[ro.build.version.sdk]: [11]',
7272
),
7373
]);
74-
final File apk = fileSystem.file('app-debug.apk')..createSync();
74+
final File apk = fileSystem.file('app.apk')..createSync();
7575
final AndroidApk androidApk = AndroidApk(
7676
applicationPackage: apk,
7777
id: 'app',
@@ -87,7 +87,7 @@ void main() {
8787
});
8888

8989
testWithoutContext('Cannot install app if APK file is missing', () async {
90-
final File apk = fileSystem.file('app-debug.apk');
90+
final File apk = fileSystem.file('app.apk');
9191
final AndroidApk androidApk = AndroidApk(
9292
applicationPackage: apk,
9393
id: 'app',
@@ -115,7 +115,7 @@ void main() {
115115
kInstallCommand,
116116
kStoreShaCommand,
117117
]);
118-
final File apk = fileSystem.file('app-debug.apk')..createSync();
118+
final File apk = fileSystem.file('app.apk')..createSync();
119119
final AndroidApk androidApk = AndroidApk(
120120
applicationPackage: apk,
121121
id: 'app',
@@ -144,7 +144,7 @@ void main() {
144144
kInstallCommand,
145145
kStoreShaCommand,
146146
]);
147-
final File apk = fileSystem.file('app-debug.apk')..createSync();
147+
final File apk = fileSystem.file('app.apk')..createSync();
148148
final AndroidApk androidApk = AndroidApk(
149149
applicationPackage: apk,
150150
id: 'app',
@@ -182,13 +182,13 @@ void main() {
182182
'-r',
183183
'--user',
184184
'jane',
185-
'app-debug.apk',
185+
'app.apk',
186186
],
187187
exitCode: 1,
188188
stderr: 'Exception occurred while executing: java.lang.IllegalArgumentException: Bad user number: jane',
189189
),
190190
]);
191-
final File apk = fileSystem.file('app-debug.apk')..createSync();
191+
final File apk = fileSystem.file('app.apk')..createSync();
192192
final AndroidApk androidApk = AndroidApk(
193193
applicationPackage: apk,
194194
id: 'app',
@@ -221,8 +221,8 @@ void main() {
221221
stdout: 'example_sha',
222222
),
223223
]);
224-
final File apk = fileSystem.file('app-debug.apk')..createSync();
225-
fileSystem.file('app-debug.apk.sha1').writeAsStringSync('example_sha');
224+
final File apk = fileSystem.file('app.apk')..createSync();
225+
fileSystem.file('app.apk.sha1').writeAsStringSync('example_sha');
226226
final AndroidApk androidApk = AndroidApk(
227227
applicationPackage: apk,
228228
id: 'app',
@@ -254,16 +254,16 @@ void main() {
254254
stdout: 'different_example_sha',
255255
),
256256
const FakeCommand(
257-
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app-debug.apk'],
257+
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app.apk'],
258258
exitCode: 1,
259259
stderr: '[INSTALL_FAILED_INSUFFICIENT_STORAGE]',
260260
),
261261
const FakeCommand(command: <String>['adb', '-s', '1234', 'uninstall', '--user', '10', 'app']),
262262
kInstallCommand,
263263
const FakeCommand(command: <String>['adb', '-s', '1234', 'shell', 'echo', '-n', 'example_sha', '>', '/data/local/tmp/sky.app.sha1']),
264264
]);
265-
final File apk = fileSystem.file('app-debug.apk')..createSync();
266-
fileSystem.file('app-debug.apk.sha1').writeAsStringSync('example_sha');
265+
final File apk = fileSystem.file('app.apk')..createSync();
266+
fileSystem.file('app.apk.sha1').writeAsStringSync('example_sha');
267267
final AndroidApk androidApk = AndroidApk(
268268
applicationPackage: apk,
269269
id: 'app',
@@ -291,12 +291,12 @@ void main() {
291291
stdout: '\n'
292292
),
293293
const FakeCommand(
294-
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app-debug.apk'],
294+
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app.apk'],
295295
exitCode: 1,
296296
stderr: '[INSTALL_FAILED_INSUFFICIENT_STORAGE]',
297297
),
298298
]);
299-
final File apk = fileSystem.file('app-debug.apk')..createSync();
299+
final File apk = fileSystem.file('app.apk')..createSync();
300300
final AndroidApk androidApk = AndroidApk(
301301
applicationPackage: apk,
302302
id: 'app',

packages/flutter_tools/test/general.shard/android/gradle_test.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,6 @@ void main() {
121121
});
122122

123123
group('listApkPaths', () {
124-
testWithoutContext('Finds APK without flavor in debug', () {
125-
final Iterable<String> apks = listApkPaths(
126-
const AndroidBuildInfo(BuildInfo(BuildMode.debug, '', treeShakeIcons: false)),
127-
);
128-
expect(apks, <String>['app-debug.apk']);
129-
});
130-
131-
testWithoutContext('Finds APK with flavor in debug', () {
132-
final Iterable<String> apks = listApkPaths(
133-
const AndroidBuildInfo(BuildInfo(BuildMode.debug, 'flavor1', treeShakeIcons: false)),
134-
);
135-
expect(apks, <String>['app-flavor1-debug.apk']);
136-
});
137-
138124
testWithoutContext('Finds APK without flavor in release', () {
139125
final Iterable<String> apks = listApkPaths(
140126
const AndroidBuildInfo(BuildInfo(BuildMode.release, '', treeShakeIcons: false)),

packages/flutter_tools/test/general.shard/application_package_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void main() {
5757

5858
testUsingContext('Licenses not available, platform and buildtools available, apk exists', () async {
5959
const String aaptPath = 'aaptPath';
60-
final File apkFile = globals.fs.file('app-debug.apk');
60+
final File apkFile = globals.fs.file('app.apk');
6161
final FakeAndroidSdkVersion sdkVersion = FakeAndroidSdkVersion();
6262
sdkVersion.aaptPath = aaptPath;
6363
sdk.latestVersion = sdkVersion;
@@ -81,7 +81,7 @@ void main() {
8181
TargetPlatform.android_arm,
8282
applicationBinary: apkFile,
8383
))!;
84-
expect(applicationPackage.name, 'app-debug.apk');
84+
expect(applicationPackage.name, 'app.apk');
8585
expect(applicationPackage, isA<PrebuiltApplicationPackage>());
8686
expect((applicationPackage as PrebuiltApplicationPackage).applicationPackage.path, apkFile.path);
8787
expect(fakeProcessManager, hasNoRemainingExpectations);
@@ -103,7 +103,7 @@ void main() {
103103

104104
await ApplicationPackageFactory.instance!.getPackageForPlatform(
105105
TargetPlatform.android_arm,
106-
applicationBinary: globals.fs.file('app-debug.apk'),
106+
applicationBinary: globals.fs.file('app.apk'),
107107
);
108108
expect(fakeProcessManager, hasNoRemainingExpectations);
109109
}, overrides: overrides);

packages/flutter_tools/test/general.shard/resident_runner_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void main() {
312312
<FlutterDevice>[
313313
flutterDevice,
314314
],
315-
applicationBinary: globals.fs.file('app-debug.apk'),
315+
applicationBinary: globals.fs.file('app.apk'),
316316
stayResident: false,
317317
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
318318
target: 'main.dart',

0 commit comments

Comments
 (0)