mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix bundle id on iOS launch using flutter run (#31039)
This commit is contained in:
parent
6a1468db16
commit
74c6237abc
@ -23,6 +23,7 @@ import '../project.dart';
|
||||
import '../protocol_discovery.dart';
|
||||
import 'ios_workflow.dart';
|
||||
import 'mac.dart';
|
||||
import 'plist_utils.dart';
|
||||
|
||||
const String _xcrunPath = '/usr/bin/xcrun';
|
||||
|
||||
@ -343,7 +344,15 @@ class IOSSimulator extends Device {
|
||||
|
||||
// Launch the updated application in the simulator.
|
||||
try {
|
||||
await SimControl.instance.launch(id, package.id, args);
|
||||
// Use the built application's Info.plist to get the bundle identifier,
|
||||
// which should always yield the correct value and does not require
|
||||
// parsing the xcodeproj or configuration files.
|
||||
// See https://github.com/flutter/flutter/issues/31037 for more information.
|
||||
final IOSApp iosApp = package;
|
||||
final String plistPath = fs.path.join(iosApp.simulatorBundlePath, 'Info.plist');
|
||||
final String bundleIdentifier = iosWorkflow.getPlistValueFromFile(plistPath, kCFBundleIdentifierKey);
|
||||
|
||||
await SimControl.instance.launch(id, bundleIdentifier, args);
|
||||
} catch (error) {
|
||||
printError('$error');
|
||||
return LaunchResult.failed();
|
||||
|
||||
@ -6,10 +6,12 @@ import 'dart:async';
|
||||
import 'dart:io' show ProcessResult, Process;
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/application_package.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/ios/ios_workflow.dart';
|
||||
import 'package:flutter_tools/src/ios/mac.dart';
|
||||
import 'package:flutter_tools/src/ios/simulators.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
@ -26,6 +28,8 @@ class MockIMobileDevice extends Mock implements IMobileDevice {}
|
||||
class MockProcess extends Mock implements Process {}
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
class MockXcode extends Mock implements Xcode {}
|
||||
class MockSimControl extends Mock implements SimControl {}
|
||||
class MockIOSWorkflow extends Mock implements IOSWorkflow {}
|
||||
|
||||
void main() {
|
||||
FakePlatform osx;
|
||||
@ -417,6 +421,33 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
group('startApp', () {
|
||||
SimControl simControl;
|
||||
|
||||
setUp(() {
|
||||
simControl = MockSimControl();
|
||||
});
|
||||
|
||||
testUsingContext("startApp uses compiled app's Info.plist to find CFBundleIdentifier", () async {
|
||||
final IOSSimulator device = IOSSimulator('x', name: 'iPhone SE', category: 'iOS 11.2');
|
||||
when(iosWorkflow.getPlistValueFromFile(any, any)).thenReturn('correct');
|
||||
|
||||
final Directory mockDir = fs.currentDirectory;
|
||||
final IOSApp package = PrebuiltIOSApp(projectBundleId: 'incorrect', bundleName: 'name', bundleDir: mockDir);
|
||||
|
||||
const BuildInfo mockInfo = BuildInfo(BuildMode.debug, 'flavor');
|
||||
final DebuggingOptions mockOptions = DebuggingOptions.disabled(mockInfo);
|
||||
await device.startApp(package, prebuiltApplication: true, debuggingOptions: mockOptions);
|
||||
|
||||
verify(simControl.launch(any, 'correct', any));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
SimControl: () => simControl,
|
||||
IOSWorkflow: () => MockIOSWorkflow()
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('IOSDevice.isSupportedForProject is true on module project', () async {
|
||||
fs.file('pubspec.yaml')
|
||||
..createSync()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user