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

This commit is contained in:
Alex Li
2022-10-18 10:06:30 +08:00
committed by GitHub
parent 2ea90eaed2
commit 0ad71e8727
8 changed files with 81 additions and 46 deletions

View File

@@ -65,7 +65,7 @@ void main() {
platform: FakePlatform(),
androidSdk: androidSdk,
);
final File apkFile = fileSystem.file('app.apk')..createSync();
final File apkFile = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk apk = AndroidApk(
id: 'FlutterApp',
applicationPackage: apkFile,
@@ -88,7 +88,7 @@ void main() {
command: <String>['adb', '-s', '1234', 'shell', 'pm', 'list', 'packages', 'FlutterApp'],
));
processManager.addCommand(const FakeCommand(
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', 'app.apk'],
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', 'app-debug.apk'],
));
processManager.addCommand(kShaCommand);
processManager.addCommand(const FakeCommand(
@@ -132,7 +132,7 @@ void main() {
platform: FakePlatform(),
androidSdk: androidSdk,
);
final File apkFile = fileSystem.file('app.apk')..createSync();
final File apkFile = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk apk = AndroidApk(
id: 'FlutterApp',
applicationPackage: apkFile,
@@ -170,7 +170,7 @@ void main() {
platform: FakePlatform(),
androidSdk: androidSdk,
);
final File apkFile = fileSystem.file('app.apk')..createSync();
final File apkFile = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk apk = AndroidApk(
id: 'FlutterApp',
applicationPackage: apkFile,
@@ -200,7 +200,7 @@ void main() {
'-r',
'--user',
'10',
'app.apk',
'app-debug.apk',
],
stdout: '\n\nThe Dart VM service is listening on http://127.0.0.1:456\n\n',
));

View File

@@ -31,7 +31,7 @@ const FakeCommand kInstallCommand = FakeCommand(
'-r',
'--user',
'10',
'app.apk',
'app-debug.apk',
],
);
const FakeCommand kStoreShaCommand = FakeCommand(
@@ -71,7 +71,7 @@ void main() {
stdout: '[ro.build.version.sdk]: [11]',
),
]);
final File apk = fileSystem.file('app.apk')..createSync();
final File apk = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',
@@ -87,7 +87,7 @@ void main() {
});
testWithoutContext('Cannot install app if APK file is missing', () async {
final File apk = fileSystem.file('app.apk');
final File apk = fileSystem.file('app-debug.apk');
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',
@@ -115,7 +115,7 @@ void main() {
kInstallCommand,
kStoreShaCommand,
]);
final File apk = fileSystem.file('app.apk')..createSync();
final File apk = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',
@@ -144,7 +144,7 @@ void main() {
kInstallCommand,
kStoreShaCommand,
]);
final File apk = fileSystem.file('app.apk')..createSync();
final File apk = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',
@@ -182,13 +182,13 @@ void main() {
'-r',
'--user',
'jane',
'app.apk',
'app-debug.apk',
],
exitCode: 1,
stderr: 'Exception occurred while executing: java.lang.IllegalArgumentException: Bad user number: jane',
),
]);
final File apk = fileSystem.file('app.apk')..createSync();
final File apk = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',
@@ -221,8 +221,8 @@ void main() {
stdout: 'example_sha',
),
]);
final File apk = fileSystem.file('app.apk')..createSync();
fileSystem.file('app.apk.sha1').writeAsStringSync('example_sha');
final File apk = fileSystem.file('app-debug.apk')..createSync();
fileSystem.file('app-debug.apk.sha1').writeAsStringSync('example_sha');
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',
@@ -254,7 +254,7 @@ void main() {
stdout: 'different_example_sha',
),
const FakeCommand(
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app.apk'],
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app-debug.apk'],
exitCode: 1,
stderr: '[INSTALL_FAILED_INSUFFICIENT_STORAGE]',
),
@@ -262,8 +262,8 @@ void main() {
kInstallCommand,
const FakeCommand(command: <String>['adb', '-s', '1234', 'shell', 'echo', '-n', 'example_sha', '>', '/data/local/tmp/sky.app.sha1']),
]);
final File apk = fileSystem.file('app.apk')..createSync();
fileSystem.file('app.apk.sha1').writeAsStringSync('example_sha');
final File apk = fileSystem.file('app-debug.apk')..createSync();
fileSystem.file('app-debug.apk.sha1').writeAsStringSync('example_sha');
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',
@@ -291,12 +291,12 @@ void main() {
stdout: '\n'
),
const FakeCommand(
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app.apk'],
command: <String>['adb', '-s', '1234', 'install', '-t', '-r', '--user', '10', 'app-debug.apk'],
exitCode: 1,
stderr: '[INSTALL_FAILED_INSUFFICIENT_STORAGE]',
),
]);
final File apk = fileSystem.file('app.apk')..createSync();
final File apk = fileSystem.file('app-debug.apk')..createSync();
final AndroidApk androidApk = AndroidApk(
applicationPackage: apk,
id: 'app',

View File

@@ -121,6 +121,20 @@ void main() {
});
group('listApkPaths', () {
testWithoutContext('Finds APK without flavor in debug', () {
final Iterable<String> apks = listApkPaths(
const AndroidBuildInfo(BuildInfo(BuildMode.debug, '', treeShakeIcons: false)),
);
expect(apks, <String>['app-debug.apk']);
});
testWithoutContext('Finds APK with flavor in debug', () {
final Iterable<String> apks = listApkPaths(
const AndroidBuildInfo(BuildInfo(BuildMode.debug, 'flavor1', treeShakeIcons: false)),
);
expect(apks, <String>['app-flavor1-debug.apk']);
});
testWithoutContext('Finds APK without flavor in release', () {
final Iterable<String> apks = listApkPaths(
const AndroidBuildInfo(BuildInfo(BuildMode.release, '', treeShakeIcons: false)),

View File

@@ -57,7 +57,7 @@ void main() {
testUsingContext('Licenses not available, platform and buildtools available, apk exists', () async {
const String aaptPath = 'aaptPath';
final File apkFile = globals.fs.file('app.apk');
final File apkFile = globals.fs.file('app-debug.apk');
final FakeAndroidSdkVersion sdkVersion = FakeAndroidSdkVersion();
sdkVersion.aaptPath = aaptPath;
sdk.latestVersion = sdkVersion;
@@ -81,7 +81,7 @@ void main() {
TargetPlatform.android_arm,
applicationBinary: apkFile,
))!;
expect(applicationPackage.name, 'app.apk');
expect(applicationPackage.name, 'app-debug.apk');
expect(applicationPackage, isA<PrebuiltApplicationPackage>());
expect((applicationPackage as PrebuiltApplicationPackage).applicationPackage.path, apkFile.path);
expect(fakeProcessManager, hasNoRemainingExpectations);
@@ -103,7 +103,7 @@ void main() {
await ApplicationPackageFactory.instance!.getPackageForPlatform(
TargetPlatform.android_arm,
applicationBinary: globals.fs.file('app.apk'),
applicationBinary: globals.fs.file('app-debug.apk'),
);
expect(fakeProcessManager, hasNoRemainingExpectations);
}, overrides: overrides);

View File

@@ -312,7 +312,7 @@ void main() {
<FlutterDevice>[
flutterDevice,
],
applicationBinary: globals.fs.file('app.apk'),
applicationBinary: globals.fs.file('app-debug.apk'),
stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',