Skip to content

Commit 162be59

Browse files
authored
[tools]build IPA validation bundle identifier using the default "com.example" prefix (#116430)
* [tools]build IPA validation bundle identifier using default com.example * rephrase the warning
1 parent 22cbef3 commit 162be59

File tree

5 files changed

+87
-81
lines changed

5 files changed

+87
-81
lines changed

dev/devicelab/bin/tasks/ios_content_validation_test.dart

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Future<void> main() async {
5353
if (!output.contains('Warning: Launch image is set to the default placeholder. Replace with unique launch images.')) {
5454
throw TaskResult.failure('Must validate template launch image.');
5555
}
56+
57+
// The project is still using com.example as bundle identifier prefix.
58+
if (!output.contains('Warning: Your application still contains the default "com.example" bundle identifier.')) {
59+
throw TaskResult.failure('Must validate the default bundle identifier prefix');
60+
}
5661
});
5762

5863
final String archivePath = path.join(

packages/flutter_tools/lib/src/commands/build_ios.dart

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
350350
if (xcodeProjectSettingsMap.values.any((String? element) => element == null)) {
351351
messageBuffer.writeln('\nYou must set up the missing settings.');
352352
}
353+
354+
if (xcodeProjectSettingsMap['Bundle Identifier']?.startsWith('com.example') ?? false) {
355+
messageBuffer.writeln('\nWarning: Your application still contains the default "com.example" bundle identifier.');
356+
}
353357
}
354358

355359
@override

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

-14
Original file line numberDiff line numberDiff line change
@@ -740,13 +740,6 @@ bool _handleIssues(XCResult? xcResult, Logger logger, XcodeBuildExecution? xcode
740740
logger.printError("Also try selecting 'Product > Build' to fix the problem.");
741741
}
742742

743-
if (!issueDetected && _needUpdateSigningIdentifier(xcodeBuildExecution)) {
744-
issueDetected = true;
745-
logger.printError('');
746-
logger.printError('It appears that your application still contains the default signing identifier.');
747-
logger.printError("Try replacing 'com.example' with your signing id in Xcode:");
748-
logger.printError(' open ios/Runner.xcworkspace');
749-
}
750743
return issueDetected;
751744
}
752745

@@ -760,13 +753,6 @@ bool _missingDevelopmentTeam(XcodeBuildExecution? xcodeBuildExecution) {
760753
xcodeBuildExecution.buildSettings.containsKey);
761754
}
762755

763-
// Return `true` if the signing identifier needs to be updated.
764-
bool _needUpdateSigningIdentifier(XcodeBuildExecution? xcodeBuildExecution) {
765-
return xcodeBuildExecution != null
766-
&& xcodeBuildExecution.environmentType == EnvironmentType.physical
767-
&& (xcodeBuildExecution.buildSettings['PRODUCT_BUNDLE_IDENTIFIER']?.contains('com.example') ?? false);
768-
}
769-
770756
// Detects and handles errors from stdout.
771757
//
772758
// As detecting issues in stdout is not usually accurate, this should be used as a fallback when other issue detecting methods failed.

packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart

-67
Original file line numberDiff line numberDiff line change
@@ -565,73 +565,6 @@ void main() {
565565
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
566566
});
567567

568-
testUsingContext('Default bundle identifier error should be hidden if there is another xcresult issue.', () async {
569-
final BuildCommand command = BuildCommand(
570-
androidSdk: FakeAndroidSdk(),
571-
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
572-
fileSystem: MemoryFileSystem.test(),
573-
logger: BufferLogger.test(),
574-
osUtils: FakeOperatingSystemUtils(),
575-
);
576-
577-
createMinimalMockProjectFiles();
578-
579-
await expectLater(
580-
createTestCommandRunner(command).run(const <String>['build', 'ios', '--no-pub']),
581-
throwsToolExit(),
582-
);
583-
584-
expect(testLogger.errorText, contains("Use of undeclared identifier 'asdas'"));
585-
expect(testLogger.errorText, contains('/Users/m/Projects/test_create/ios/Runner/AppDelegate.m:7:56'));
586-
expect(testLogger.errorText, isNot(contains('It appears that your application still contains the default signing identifier.')));
587-
}, overrides: <Type, Generator>{
588-
FileSystem: () => fileSystem,
589-
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
590-
xattrCommand,
591-
setUpFakeXcodeBuildHandler(exitCode: 1, onRun: () {
592-
fileSystem.systemTempDirectory.childDirectory(_xcBundleFilePath).createSync();
593-
}),
594-
setUpXCResultCommand(stdout: kSampleResultJsonWithIssues),
595-
setUpRsyncCommand(),
596-
]),
597-
Platform: () => macosPlatform,
598-
EnvironmentType: () => EnvironmentType.physical,
599-
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(productBundleIdentifier: 'com.example'),
600-
});
601-
602-
testUsingContext('Show default bundle identifier error if there are no other errors.', () async {
603-
final BuildCommand command = BuildCommand(
604-
androidSdk: FakeAndroidSdk(),
605-
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
606-
fileSystem: MemoryFileSystem.test(),
607-
logger: BufferLogger.test(),
608-
osUtils: FakeOperatingSystemUtils(),
609-
);
610-
611-
createMinimalMockProjectFiles();
612-
613-
await expectLater(
614-
createTestCommandRunner(command).run(const <String>['build', 'ios', '--no-pub']),
615-
throwsToolExit(),
616-
);
617-
618-
expect(testLogger.errorText, contains('It appears that your application still contains the default signing identifier.'));
619-
}, overrides: <Type, Generator>{
620-
FileSystem: () => fileSystem,
621-
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
622-
xattrCommand,
623-
setUpFakeXcodeBuildHandler(exitCode: 1, onRun: () {
624-
fileSystem.systemTempDirectory.childDirectory(_xcBundleFilePath).createSync();
625-
}),
626-
setUpXCResultCommand(stdout: kSampleResultJsonNoIssues),
627-
setUpRsyncCommand(),
628-
]),
629-
Platform: () => macosPlatform,
630-
EnvironmentType: () => EnvironmentType.physical,
631-
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(productBundleIdentifier: 'com.example'),
632-
});
633-
634-
635568
testUsingContext('Display xcresult issues with no provisioning profile.', () async {
636569
final BuildCommand command = BuildCommand(
637570
androidSdk: FakeAndroidSdk(),

packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart

+78
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,84 @@ void main() {
991991
PlistParser: () => plistUtils,
992992
});
993993

994+
testUsingContext(
995+
'Validate basic Xcode settings with default bundle identifier prefix', () async {
996+
const String plistPath = 'build/ios/archive/Runner.xcarchive/Products/Applications/Runner.app/Info.plist';
997+
fakeProcessManager.addCommands(<FakeCommand>[
998+
xattrCommand,
999+
setUpFakeXcodeBuildHandler(onRun: () {
1000+
fileSystem.file(plistPath).createSync(recursive: true);
1001+
}),
1002+
exportArchiveCommand(exportOptionsPlist: _exportOptionsPlist),
1003+
]);
1004+
1005+
createMinimalMockProjectFiles();
1006+
1007+
plistUtils.fileContents[plistPath] = <String,String>{
1008+
'CFBundleIdentifier': 'com.example.my_app',
1009+
};
1010+
1011+
final BuildCommand command = BuildCommand(
1012+
androidSdk: FakeAndroidSdk(),
1013+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
1014+
fileSystem: MemoryFileSystem.test(),
1015+
logger: BufferLogger.test(),
1016+
osUtils: FakeOperatingSystemUtils(),
1017+
);
1018+
await createTestCommandRunner(command).run(
1019+
<String>['build', 'ipa', '--no-pub']);
1020+
1021+
expect(
1022+
testLogger.statusText,
1023+
contains('Warning: Your application still contains the default "com.example" bundle identifier.')
1024+
);
1025+
}, overrides: <Type, Generator>{
1026+
FileSystem: () => fileSystem,
1027+
ProcessManager: () => fakeProcessManager,
1028+
Platform: () => macosPlatform,
1029+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
1030+
PlistParser: () => plistUtils,
1031+
});
1032+
1033+
testUsingContext(
1034+
'Validate basic Xcode settings with custom bundle identifier prefix', () async {
1035+
const String plistPath = 'build/ios/archive/Runner.xcarchive/Products/Applications/Runner.app/Info.plist';
1036+
fakeProcessManager.addCommands(<FakeCommand>[
1037+
xattrCommand,
1038+
setUpFakeXcodeBuildHandler(onRun: () {
1039+
fileSystem.file(plistPath).createSync(recursive: true);
1040+
}),
1041+
exportArchiveCommand(exportOptionsPlist: _exportOptionsPlist),
1042+
]);
1043+
1044+
createMinimalMockProjectFiles();
1045+
1046+
plistUtils.fileContents[plistPath] = <String,String>{
1047+
'CFBundleIdentifier': 'com.my_company.my_app',
1048+
};
1049+
1050+
final BuildCommand command = BuildCommand(
1051+
androidSdk: FakeAndroidSdk(),
1052+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
1053+
fileSystem: MemoryFileSystem.test(),
1054+
logger: BufferLogger.test(),
1055+
osUtils: FakeOperatingSystemUtils(),
1056+
);
1057+
await createTestCommandRunner(command).run(
1058+
<String>['build', 'ipa', '--no-pub']);
1059+
1060+
expect(
1061+
testLogger.statusText,
1062+
isNot(contains('Warning: Your application still contains the default "com.example" bundle identifier.'))
1063+
);
1064+
}, overrides: <Type, Generator>{
1065+
FileSystem: () => fileSystem,
1066+
ProcessManager: () => fakeProcessManager,
1067+
Platform: () => macosPlatform,
1068+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
1069+
PlistParser: () => plistUtils,
1070+
});
1071+
9941072

9951073
testUsingContext('Validate template app icons with conflicts', () async {
9961074
const String projectIconContentsJsonPath = 'ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json';

0 commit comments

Comments
 (0)