[tools]validation basic Xcode settings for build ipa (#113412)
This commit is contained in:
@@ -15,6 +15,7 @@ import '../convert.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../ios/application_package.dart';
|
||||
import '../ios/mac.dart';
|
||||
import '../ios/plist_parser.dart';
|
||||
import '../runner/flutter_command.dart';
|
||||
import 'build.dart';
|
||||
|
||||
@@ -129,12 +130,49 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
|
||||
return super.validateCommand();
|
||||
}
|
||||
|
||||
Future<void> _validateXcodeBuildSettingsAfterArchive() async {
|
||||
final BuildableIOSApp app = await buildableIOSApp;
|
||||
|
||||
final String plistPath = app.builtInfoPlistPathAfterArchive;
|
||||
|
||||
if (!globals.fs.file(plistPath).existsSync()) {
|
||||
globals.printError('Invalid iOS archive. Does not contain Info.plist.');
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, String?> xcodeProjectSettingsMap = <String, String?>{};
|
||||
|
||||
xcodeProjectSettingsMap['Version Number'] = globals.plistParser.getStringValueFromFile(plistPath, PlistParser.kCFBundleShortVersionStringKey);
|
||||
xcodeProjectSettingsMap['Build Number'] = globals.plistParser.getStringValueFromFile(plistPath, PlistParser.kCFBundleVersionKey);
|
||||
xcodeProjectSettingsMap['Display Name'] = globals.plistParser.getStringValueFromFile(plistPath, PlistParser.kCFBundleDisplayNameKey);
|
||||
xcodeProjectSettingsMap['Deployment Target'] = globals.plistParser.getStringValueFromFile(plistPath, PlistParser.kMinimumOSVersionKey);
|
||||
xcodeProjectSettingsMap['Bundle Identifier'] = globals.plistParser.getStringValueFromFile(plistPath, PlistParser.kCFBundleIdentifierKey);
|
||||
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
xcodeProjectSettingsMap.forEach((String title, String? info) {
|
||||
buffer.writeln('$title: ${info ?? "Missing"}');
|
||||
});
|
||||
|
||||
final String message;
|
||||
if (xcodeProjectSettingsMap.values.any((String? element) => element == null)) {
|
||||
buffer.writeln('\nYou must set up the missing settings');
|
||||
buffer.write('Instructions: https://docs.flutter.dev/deployment/ios');
|
||||
message = buffer.toString();
|
||||
} else {
|
||||
// remove the new line
|
||||
message = buffer.toString().trim();
|
||||
}
|
||||
globals.printBox(message, title: 'App Settings');
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
final BuildInfo buildInfo = await cachedBuildInfo;
|
||||
displayNullSafetyMode(buildInfo);
|
||||
final FlutterCommandResult xcarchiveResult = await super.runCommand();
|
||||
|
||||
await _validateXcodeBuildSettingsAfterArchive();
|
||||
|
||||
// xcarchive failed or not at expected location.
|
||||
if (xcarchiveResult.exitStatus != ExitStatus.success) {
|
||||
globals.printStatus('Skipping IPA.');
|
||||
@@ -289,6 +327,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
|
||||
/// The result of the Xcode build command. Null until it finishes.
|
||||
@protected
|
||||
XcodeBuildResult? xcodeBuildResult;
|
||||
|
||||
EnvironmentType get environmentType;
|
||||
bool get configOnly;
|
||||
|
||||
|
||||
@@ -145,6 +145,12 @@ class BuildableIOSApp extends IOSApp {
|
||||
String get archiveBundleOutputPath =>
|
||||
globals.fs.path.setExtension(archiveBundlePath, '.xcarchive');
|
||||
|
||||
String get builtInfoPlistPathAfterArchive => globals.fs.path.join(archiveBundleOutputPath,
|
||||
'Products',
|
||||
'Applications',
|
||||
_hostAppBundleName == null ? 'Runner.app' : _hostAppBundleName!,
|
||||
'Info.plist');
|
||||
|
||||
String get ipaOutputPath =>
|
||||
globals.fs.path.join(getIosBuildDirectory(), 'ipa');
|
||||
|
||||
|
||||
@@ -26,7 +26,10 @@ class PlistParser {
|
||||
|
||||
static const String kCFBundleIdentifierKey = 'CFBundleIdentifier';
|
||||
static const String kCFBundleShortVersionStringKey = 'CFBundleShortVersionString';
|
||||
static const String kCFBundleExecutable = 'CFBundleExecutable';
|
||||
static const String kCFBundleExecutableKey = 'CFBundleExecutable';
|
||||
static const String kCFBundleVersionKey = 'CFBundleVersion';
|
||||
static const String kCFBundleDisplayNameKey = 'CFBundleDisplayName';
|
||||
static const String kMinimumOSVersionKey = 'MinimumOSVersion';
|
||||
|
||||
/// Returns the content, converted to XML, of the plist file located at
|
||||
/// [plistFilePath].
|
||||
|
||||
@@ -87,7 +87,7 @@ abstract class MacOSApp extends ApplicationPackage {
|
||||
}
|
||||
final Map<String, dynamic> propertyValues = globals.plistParser.parseFile(plistPath);
|
||||
final String? id = propertyValues[PlistParser.kCFBundleIdentifierKey] as String?;
|
||||
final String? executableName = propertyValues[PlistParser.kCFBundleExecutable] as String?;
|
||||
final String? executableName = propertyValues[PlistParser.kCFBundleExecutableKey] as String?;
|
||||
if (id == null) {
|
||||
globals.printError('Invalid prebuilt macOS app. Info.plist does not contain bundle identifier');
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user