Skip to content

Commit 9f5c655

Browse files
authored
Revert "Check for watch companion in build settings (#113956)" (#114035)
This reverts commit e133721.
1 parent e133721 commit 9f5c655

File tree

7 files changed

+29
-291
lines changed

7 files changed

+29
-291
lines changed

dev/integration_tests/ios_app_with_extensions/ios/Runner.xcodeproj/project.pbxproj

-3
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@
727727
GCC_C_LANGUAGE_STANDARD = gnu11;
728728
IBSC_MODULE = watch_Extension;
729729
INFOPLIST_FILE = watch/Info.plist;
730-
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = io.flutter.extensionTest;
731730
MARKETING_VERSION = 1.0.0;
732731
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
733732
MTL_FAST_MATH = YES;
@@ -758,7 +757,6 @@
758757
GCC_C_LANGUAGE_STANDARD = gnu11;
759758
IBSC_MODULE = watch_Extension;
760759
INFOPLIST_FILE = watch/Info.plist;
761-
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = io.flutter.extensionTest;
762760
MARKETING_VERSION = 1.0.0;
763761
MTL_FAST_MATH = YES;
764762
OTHER_LDFLAGS = "";
@@ -787,7 +785,6 @@
787785
GCC_C_LANGUAGE_STANDARD = gnu11;
788786
IBSC_MODULE = watch_Extension;
789787
INFOPLIST_FILE = watch/Info.plist;
790-
INFOPLIST_KEY_WKCompanionAppBundleIdentifier = io.flutter.extensionTest;
791788
MARKETING_VERSION = 1.0.0;
792789
MTL_FAST_MATH = YES;
793790
OTHER_LDFLAGS = "";

dev/integration_tests/ios_app_with_extensions/ios/watch/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<string>UIInterfaceOrientationPortrait</string>
2626
<string>UIInterfaceOrientationPortraitUpsideDown</string>
2727
</array>
28+
<key>WKCompanionAppBundleIdentifier</key>
29+
<string>$(APP_BUNDLE_IDENTIFIER)</string>
2830
<key>WKWatchKitApp</key>
2931
<true/>
3032
</dict>

packages/flutter_tools/lib/src/ios/mac.dart

+3-4
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,9 @@ Future<XcodeBuildResult> buildXcodeProject({
265265

266266
// Check if the project contains a watchOS companion app.
267267
final bool hasWatchCompanion = await app.project.containsWatchCompanion(
268-
targets: projectInfo.targets,
269-
schemes: projectInfo.schemes,
270-
buildInfo: buildInfo,
271-
deviceId: deviceID,
268+
projectInfo.targets,
269+
buildInfo,
270+
deviceID,
272271
);
273272
if (hasWatchCompanion) {
274273
// The -sdk argument has to be omitted if a watchOS companion app exists.

packages/flutter_tools/lib/src/ios/xcodeproj.dart

+2-9
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,7 @@ class XcodeProjectInterpreter {
198198
if (buildContext.environmentType == EnvironmentType.simulator)
199199
...<String>['-sdk', 'iphonesimulator'],
200200
'-destination',
201-
if (buildContext.isWatch == true && buildContext.environmentType == EnvironmentType.physical)
202-
'generic/platform=watchOS'
203-
else if (buildContext.isWatch == true)
204-
'generic/platform=watchOS Simulator'
205-
else if (deviceId != null)
201+
if (deviceId != null)
206202
'id=$deviceId'
207203
else if (buildContext.environmentType == EnvironmentType.physical)
208204
'generic/platform=iOS'
@@ -380,14 +376,12 @@ class XcodeProjectBuildContext {
380376
this.configuration,
381377
this.environmentType = EnvironmentType.physical,
382378
this.deviceId,
383-
this.isWatch = false,
384379
});
385380

386381
final String? scheme;
387382
final String? configuration;
388383
final EnvironmentType environmentType;
389384
final String? deviceId;
390-
final bool isWatch;
391385

392386
@override
393387
int get hashCode => Object.hash(scheme, configuration, environmentType, deviceId);
@@ -401,8 +395,7 @@ class XcodeProjectBuildContext {
401395
other.scheme == scheme &&
402396
other.configuration == configuration &&
403397
other.deviceId == deviceId &&
404-
other.environmentType == environmentType &&
405-
other.isWatch == isWatch;
398+
other.environmentType == environmentType;
406399
}
407400
}
408401

packages/flutter_tools/lib/src/xcode_project.dart

+5-43
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ class IosProject extends XcodeBasedProject {
256256
BuildInfo? buildInfo, {
257257
EnvironmentType environmentType = EnvironmentType.physical,
258258
String? deviceId,
259-
String? scheme,
260-
bool isWatch = false,
261259
}) async {
262260
if (!existsSync()) {
263261
return null;
@@ -267,11 +265,9 @@ class IosProject extends XcodeBasedProject {
267265
return null;
268266
}
269267

268+
final String? scheme = info.schemeFor(buildInfo);
270269
if (scheme == null) {
271-
scheme = info.schemeFor(buildInfo);
272-
if (scheme == null) {
273-
info.reportFlavorNotFoundAndExit();
274-
}
270+
info.reportFlavorNotFoundAndExit();
275271
}
276272

277273
final String? configuration = (await projectInfo())?.buildConfigurationFor(
@@ -283,7 +279,6 @@ class IosProject extends XcodeBasedProject {
283279
scheme: scheme,
284280
configuration: configuration,
285281
deviceId: deviceId,
286-
isWatch: isWatch,
287282
);
288283
final Map<String, String>? currentBuildSettings = _buildSettingsByBuildContext[buildContext];
289284
if (currentBuildSettings == null) {
@@ -332,12 +327,7 @@ class IosProject extends XcodeBasedProject {
332327
}
333328

334329
/// Check if one the [targets] of the project is a watchOS companion app target.
335-
Future<bool> containsWatchCompanion({
336-
required List<String> targets,
337-
required List<String> schemes,
338-
required BuildInfo buildInfo,
339-
String? deviceId,
340-
}) async {
330+
Future<bool> containsWatchCompanion(List<String> targets, BuildInfo buildInfo, String? deviceId) async {
341331
final String? bundleIdentifier = await productBundleIdentifier(buildInfo);
342332
// A bundle identifier is required for a companion app.
343333
if (bundleIdentifier == null) {
@@ -346,8 +336,8 @@ class IosProject extends XcodeBasedProject {
346336
for (final String target in targets) {
347337
// Create Info.plist file of the target.
348338
final File infoFile = hostAppRoot.childDirectory(target).childFile('Info.plist');
349-
// In older versions of Xcode, if the target was a watchOS companion app,
350-
// the Info.plist file of the target contained the key WKCompanionAppBundleIdentifier.
339+
// The Info.plist file of a target contains the key WKCompanionAppBundleIdentifier,
340+
// if it is a watchOS companion app.
351341
if (infoFile.existsSync()) {
352342
final String? fromPlist = globals.plistParser.getStringValueFromFile(infoFile.path, 'WKCompanionAppBundleIdentifier');
353343
if (bundleIdentifier == fromPlist) {
@@ -367,34 +357,6 @@ class IosProject extends XcodeBasedProject {
367357
}
368358
}
369359
}
370-
371-
// If key not found in Info.plist above, do more expensive check of build settings.
372-
// In newer versions of Xcode, the build settings of the watchOS companion
373-
// app's scheme should contain the key INFOPLIST_KEY_WKCompanionAppBundleIdentifier.
374-
final bool watchIdentifierFound = xcodeProjectInfoFile.readAsStringSync().contains('WKCompanionAppBundleIdentifier');
375-
if (watchIdentifierFound == false) {
376-
return false;
377-
}
378-
for (final String scheme in schemes) {
379-
final Map<String, String>? allBuildSettings = await buildSettingsForBuildInfo(
380-
buildInfo,
381-
deviceId: deviceId,
382-
scheme: scheme,
383-
isWatch: true,
384-
);
385-
if (allBuildSettings != null) {
386-
final String? fromBuild = allBuildSettings['INFOPLIST_KEY_WKCompanionAppBundleIdentifier'];
387-
if (bundleIdentifier == fromBuild) {
388-
return true;
389-
}
390-
if (fromBuild != null && fromBuild.contains(r'$')) {
391-
final String substitutedVariable = substituteXcodeVariables(fromBuild, allBuildSettings);
392-
if (substitutedVariable == bundleIdentifier) {
393-
return true;
394-
}
395-
}
396-
}
397-
}
398360
return false;
399361
}
400362

packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart

-70
Original file line numberDiff line numberDiff line change
@@ -395,76 +395,6 @@ void main() {
395395
ProcessManager: () => FakeProcessManager.any(),
396396
});
397397

398-
testUsingContext('build settings uses watch destination if isWatch is true', () async {
399-
platform.environment = const <String, String>{};
400-
401-
fakeProcessManager.addCommands(<FakeCommand>[
402-
kWhichSysctlCommand,
403-
kx64CheckCommand,
404-
FakeCommand(
405-
command: <String>[
406-
'xcrun',
407-
'xcodebuild',
408-
'-project',
409-
'/',
410-
'-destination',
411-
'generic/platform=watchOS',
412-
'-showBuildSettings',
413-
'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
414-
],
415-
exitCode: 1,
416-
),
417-
]);
418-
419-
expect(
420-
await xcodeProjectInterpreter.getBuildSettings(
421-
'',
422-
buildContext: const XcodeProjectBuildContext(isWatch: true),
423-
),
424-
const <String, String>{},
425-
);
426-
expect(fakeProcessManager, hasNoRemainingExpectations);
427-
}, overrides: <Type, Generator>{
428-
FileSystem: () => fileSystem,
429-
ProcessManager: () => FakeProcessManager.any(),
430-
});
431-
432-
testUsingContext('build settings uses watch simulator destination if isWatch is true and environment type is simulator', () async {
433-
platform.environment = const <String, String>{};
434-
435-
fakeProcessManager.addCommands(<FakeCommand>[
436-
kWhichSysctlCommand,
437-
kx64CheckCommand,
438-
FakeCommand(
439-
command: <String>[
440-
'xcrun',
441-
'xcodebuild',
442-
'-project',
443-
'/',
444-
'-sdk',
445-
'iphonesimulator',
446-
'-destination',
447-
'generic/platform=watchOS Simulator',
448-
'-showBuildSettings',
449-
'BUILD_DIR=${fileSystem.path.absolute('build', 'ios')}',
450-
],
451-
exitCode: 1,
452-
),
453-
]);
454-
455-
expect(
456-
await xcodeProjectInterpreter.getBuildSettings(
457-
'',
458-
buildContext: const XcodeProjectBuildContext(environmentType: EnvironmentType.simulator, isWatch: true),
459-
),
460-
const <String, String>{},
461-
);
462-
expect(fakeProcessManager, hasNoRemainingExpectations);
463-
}, overrides: <Type, Generator>{
464-
FileSystem: () => fileSystem,
465-
ProcessManager: () => FakeProcessManager.any(),
466-
});
467-
468398
testWithoutContext('xcodebuild clean contains Flutter Xcode environment variables', () async {
469399
platform.environment = const <String, String>{
470400
'FLUTTER_XCODE_CODE_SIGN_STYLE': 'Manual',

0 commit comments

Comments
 (0)