Skip to content

Commit 3a27301

Browse files
Fix iOS reference in macOS Cocoapods error (flutter#148506)
Fixes a Cocoapods error message that was hard-coded to reference iOS to instead reference iOS or macOS as appropriate. Fixes flutter#146744
1 parent 43c6f7d commit 3a27301

File tree

2 files changed

+89
-19
lines changed

2 files changed

+89
-19
lines changed

packages/flutter_tools/lib/src/macos/cocoapods.dart

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,24 @@ class CocoaPods {
427427
final ({String failingPod, String sourcePlugin, String podPluginSubdir})?
428428
podInfo = _parseMinDeploymentFailureInfo(stdout);
429429
if (podInfo != null) {
430+
final Directory symlinksDir;
431+
final String podPlatformString;
432+
final String platformName;
433+
final String docsLink;
434+
if (xcodeProject is IosProject) {
435+
symlinksDir = xcodeProject.symlinks;
436+
podPlatformString = 'ios';
437+
platformName = 'iOS';
438+
docsLink = 'https://docs.flutter.dev/deployment/ios';
439+
} else if (xcodeProject is MacOSProject) {
440+
symlinksDir = xcodeProject.ephemeralDirectory.childDirectory('.symlinks');
441+
podPlatformString = 'osx';
442+
platformName = 'macOS';
443+
docsLink = 'https://docs.flutter.dev/deployment/macos';
444+
} else {
445+
return;
446+
}
447+
430448
final String sourcePlugin = podInfo.sourcePlugin;
431449
// If the plugin's podfile has set its own minimum version correctly
432450
// based on the requirements of its dependencies the failing pod should
@@ -435,23 +453,6 @@ class CocoaPods {
435453
// with a minimum version of 12, then building for 11 will report that
436454
// pod as failing.)
437455
if (podInfo.failingPod == podInfo.sourcePlugin) {
438-
final Directory symlinksDir;
439-
final String podPlatformString;
440-
final String platformName;
441-
final String docsLink;
442-
if (xcodeProject is IosProject) {
443-
symlinksDir = xcodeProject.symlinks;
444-
podPlatformString = 'ios';
445-
platformName = 'iOS';
446-
docsLink = 'https://docs.flutter.dev/deployment/ios';
447-
} else if (xcodeProject is MacOSProject) {
448-
symlinksDir = xcodeProject.ephemeralDirectory.childDirectory('.symlinks');
449-
podPlatformString = 'osx';
450-
platformName = 'macOS';
451-
docsLink = 'https://docs.flutter.dev/deployment/macos';
452-
} else {
453-
return;
454-
}
455456
final File podspec = symlinksDir
456457
.childDirectory('plugins')
457458
.childDirectory(sourcePlugin)
@@ -493,8 +494,8 @@ class CocoaPods {
493494
// with the plugin developer.
494495
_logger.printError(
495496
'Error: The pod "${podInfo.failingPod}" required by the plugin '
496-
'"$sourcePlugin" requires a higher minimum iOS deployment version '
497-
"than the plugin's reported minimum version.\n"
497+
'"$sourcePlugin" requires a higher minimum $platformName deployment '
498+
"version than the plugin's reported minimum version.\n"
498499
'To build, remove the plugin "$sourcePlugin", or contact the plugin\'s '
499500
'developers for assistance.',
500501
emphasis: true,

packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,75 @@ Specs satisfying the `GoogleMaps (~> 8.0)` dependency were found, but they requi
836836
);
837837
});
838838

839+
testUsingContext('throws if plugin has a dependency that requires a higher minimum macOS version', () async {
840+
final FlutterProject projectUnderTest = setupProjectUnderTest();
841+
pretendPodIsInstalled();
842+
pretendPodVersionIs('100.0.0');
843+
fileSystem.file(fileSystem.path.join('project', 'macos', 'Podfile'))
844+
..createSync()
845+
..writeAsStringSync('Existing Podfile');
846+
847+
fakeProcessManager.addCommand(
848+
const FakeCommand(
849+
command: <String>['pod', 'install', '--verbose'],
850+
workingDirectory: 'project/macos',
851+
environment: <String, String>{
852+
'COCOAPODS_DISABLE_STATS': 'true',
853+
'LANG': 'en_US.UTF-8',
854+
},
855+
exitCode: 1,
856+
// This is the (very slightly abridged) output from updating the
857+
// minimum version of the GoogleMaps dependency in
858+
// google_maps_flutter_ios without updating the minimum iOS version to
859+
// match, as an example of a misconfigured plugin, but with the paths
860+
// modified to simulate a macOS plugin.
861+
stdout: '''
862+
Analyzing dependencies
863+
864+
Inspecting targets to integrate
865+
Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
866+
Using `ARCHS` setting to build architectures of target `Pods-RunnerTests`: (``)
867+
868+
Fetching external sources
869+
-> Fetching podspec for `Flutter` from `Flutter`
870+
-> Fetching podspec for `google_maps_flutter_ios` from `.symlinks/plugins/google_maps_flutter_ios/macos`
871+
872+
Resolving dependencies of `Podfile`
873+
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update
874+
CDN: trunk Relative path: Specs/a/d/d/GoogleMaps/8.0.0/GoogleMaps.podspec.json exists! Returning local because checking is only performed in repo update
875+
[!] CocoaPods could not find compatible versions for pod "GoogleMaps":
876+
In Podfile:
877+
google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/macos`) was resolved to 0.0.1, which depends on
878+
GoogleMaps (~> 8.0)
879+
880+
Specs satisfying the `GoogleMaps (~> 8.0)` dependency were found, but they required a higher minimum deployment target.''',
881+
),
882+
);
883+
884+
await expectLater(cocoaPodsUnderTest.processPods(
885+
xcodeProject: projectUnderTest.macos,
886+
buildMode: BuildMode.debug,
887+
), throwsToolExit());
888+
expect(
889+
logger.errorText,
890+
contains(
891+
'The pod "GoogleMaps" required by the plugin "google_maps_flutter_ios" '
892+
"requires a higher minimum macOS deployment version than the plugin's "
893+
'reported minimum version.'
894+
),
895+
);
896+
// The error should tell the user to contact the plugin author, as this
897+
// case is hard for us to give exact advice on, and should only be
898+
// possible if there's a mistake in the plugin's podspec.
899+
expect(
900+
logger.errorText,
901+
contains(
902+
'To build, remove the plugin "google_maps_flutter_ios", or contact '
903+
"the plugin's developers for assistance.",
904+
),
905+
);
906+
});
907+
839908
testUsingContext('throws if plugin requires higher minimum macOS version using "platform"', () async {
840909
final FlutterProject projectUnderTest = setupProjectUnderTest();
841910
pretendPodIsInstalled();

0 commit comments

Comments
 (0)