diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 0a7348383b..5b7653d5bd 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -581,16 +581,6 @@ Future diagnoseXcodeBuildFailure(XcodeBuildResult result, Usage flutterUsa // Fallback to use stdout to detect and print issues. _parseIssueInStdout(xcodeBuildExecution, logger, result); } - - if (xcodeBuildExecution != null - && xcodeBuildExecution.environmentType == EnvironmentType.physical - && (xcodeBuildExecution.buildSettings['PRODUCT_BUNDLE_IDENTIFIER']?.contains('com.example') ?? false)) { - logger.printError(''); - logger.printError('It appears that your application still contains the default signing identifier.'); - logger.printError("Try replacing 'com.example' with your signing id in Xcode:"); - logger.printError(' open ios/Runner.xcworkspace'); - return; - } } /// xcodebuild parameter (see man xcodebuild for details). @@ -757,6 +747,14 @@ bool _handleIssues(XCResult? xcResult, Logger logger, XcodeBuildExecution? xcode logger.printError(''); logger.printError("Also try selecting 'Product > Build' to fix the problem."); } + + if (!issueDetected && _needUpdateSigningIdentifier(xcodeBuildExecution)) { + issueDetected = true; + logger.printError(''); + logger.printError('It appears that your application still contains the default signing identifier.'); + logger.printError("Try replacing 'com.example' with your signing id in Xcode:"); + logger.printError(' open ios/Runner.xcworkspace'); + } return issueDetected; } @@ -769,6 +767,14 @@ bool _missingDevelopmentTeam(XcodeBuildExecution? xcodeBuildExecution) { !['DEVELOPMENT_TEAM', 'PROVISIONING_PROFILE'].any( xcodeBuildExecution.buildSettings.containsKey); } + +// Return `true` if the signing identifier needs to be updated. +bool _needUpdateSigningIdentifier(XcodeBuildExecution? xcodeBuildExecution) { + return xcodeBuildExecution != null + && xcodeBuildExecution.environmentType == EnvironmentType.physical + && (xcodeBuildExecution.buildSettings['PRODUCT_BUNDLE_IDENTIFIER']?.contains('com.example') ?? false); +} + // Detects and handles errors from stdout. // // As detecting issues in stdout is not usually accurate, this should be used as a fallback when other issue detecting methods failed. diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart index 0a85e9717e..9cd15a4c58 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart @@ -480,7 +480,7 @@ void main() { XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(), }); - testUsingContext('Display xcresult issues with default bundle identifier.', () async { + testUsingContext('Default bundle identifier error should be hidden if there is another xcresult issue.', () async { final BuildCommand command = BuildCommand(); _createMinimalMockProjectFiles(); @@ -492,7 +492,7 @@ void main() { expect(testLogger.errorText, contains("Use of undeclared identifier 'asdas'")); expect(testLogger.errorText, contains('/Users/m/Projects/test_create/ios/Runner/AppDelegate.m:7:56')); - expect(testLogger.errorText, contains('It appears that your application still contains the default signing identifier.')); + expect(testLogger.errorText, isNot(contains('It appears that your application still contains the default signing identifier.'))); }, overrides: { FileSystem: () => fileSystem, ProcessManager: () => FakeProcessManager.list([ @@ -508,6 +508,33 @@ void main() { XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(productBundleIdentifier: 'com.example'), }); + testUsingContext('Show default bundle identifier error if there are no other errors.', () async { + final BuildCommand command = BuildCommand(); + + _createMinimalMockProjectFiles(); + + await expectLater( + createTestCommandRunner(command).run(const ['build', 'ios', '--no-pub']), + throwsToolExit(), + ); + + expect(testLogger.errorText, contains('It appears that your application still contains the default signing identifier.')); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => FakeProcessManager.list([ + xattrCommand, + _setUpFakeXcodeBuildHandler(exitCode: 1, onRun: () { + fileSystem.systemTempDirectory.childDirectory(_xcBundleFilePath).createSync(); + }), + _setUpXCResultCommand(stdout: kSampleResultJsonNoIssues), + _setUpRsyncCommand(), + ]), + Platform: () => macosPlatform, + EnvironmentType: () => EnvironmentType.physical, + XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(productBundleIdentifier: 'com.example'), + }); + + testUsingContext('Display xcresult issues with no provisioning profile.', () async { final BuildCommand command = BuildCommand();