Ensure Xcode project is setup to start debugger (#136977)
Some users have their Xcode settings set to not debug (see example here https://github.com/flutter/flutter/issues/136197#issuecomment-1766834195). This will cause the [engine check for a debugger](22ce5c6a45/runtime/ptrace_check.cc (L56-L71)) to fail, which will cause an error and cause the app to crash.
This PR parses the scheme file to ensure the scheme is set to start a debugger and warn the user if it's not.
Fixes https://github.com/flutter/flutter/issues/136197.
This commit is contained in:
committed by
GitHub
parent
9366170e84
commit
5dd2a4e0aa
@@ -877,6 +877,8 @@ class IOSDevice extends Device {
|
||||
projectInfo.reportFlavorNotFoundAndExit();
|
||||
}
|
||||
|
||||
_xcodeDebug.ensureXcodeDebuggerLaunchAction(project.xcodeProjectSchemeFile(scheme: scheme));
|
||||
|
||||
debugProject = XcodeDebugProject(
|
||||
scheme: scheme,
|
||||
xcodeProject: project.xcodeProject,
|
||||
|
||||
@@ -6,7 +6,10 @@ import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:xml/xml.dart';
|
||||
import 'package:xml/xpath.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/error_handling_io.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
@@ -58,7 +61,6 @@ class XcodeDebug {
|
||||
required String deviceId,
|
||||
required List<String> launchArguments,
|
||||
}) async {
|
||||
|
||||
// If project is not already opened in Xcode, open it.
|
||||
if (!await _isProjectOpenInXcode(project: project)) {
|
||||
final bool openResult = await _openProjectInXcode(xcodeWorkspace: project.xcodeWorkspace);
|
||||
@@ -411,6 +413,49 @@ class XcodeDebug {
|
||||
verboseLogging: verboseLogging,
|
||||
);
|
||||
}
|
||||
|
||||
/// Ensure the Xcode project is set up to launch an LLDB debugger. If these
|
||||
/// settings are not set, the launch will fail with a "Cannot create a
|
||||
/// FlutterEngine instance in debug mode without Flutter tooling or Xcode."
|
||||
/// error message. These settings should be correct by default, but some users
|
||||
/// reported them not being so after upgrading to Xcode 15.
|
||||
void ensureXcodeDebuggerLaunchAction(File schemeFile) {
|
||||
if (!schemeFile.existsSync()) {
|
||||
_logger.printError('Failed to find ${schemeFile.path}');
|
||||
return;
|
||||
}
|
||||
|
||||
final String schemeXml = schemeFile.readAsStringSync();
|
||||
try {
|
||||
final XmlDocument document = XmlDocument.parse(schemeXml);
|
||||
final Iterable<XmlNode> nodes = document.xpath('/Scheme/LaunchAction');
|
||||
if (nodes.isEmpty) {
|
||||
_logger.printError('Failed to find LaunchAction for the Scheme in ${schemeFile.path}.');
|
||||
return;
|
||||
}
|
||||
final XmlNode launchAction = nodes.first;
|
||||
final XmlAttribute? debuggerIdentifer = launchAction.attributes
|
||||
.where((XmlAttribute attribute) =>
|
||||
attribute.localName == 'selectedDebuggerIdentifier')
|
||||
.firstOrNull;
|
||||
final XmlAttribute? launcherIdentifer = launchAction.attributes
|
||||
.where((XmlAttribute attribute) =>
|
||||
attribute.localName == 'selectedLauncherIdentifier')
|
||||
.firstOrNull;
|
||||
if (debuggerIdentifer == null ||
|
||||
launcherIdentifer == null ||
|
||||
!debuggerIdentifer.value.contains('LLDB') ||
|
||||
!launcherIdentifer.value.contains('LLDB')) {
|
||||
throwToolExit('''
|
||||
Your Xcode project is not setup to start a debugger. To fix this, launch Xcode
|
||||
and select "Product > Scheme > Edit Scheme", select "Run" in the sidebar,
|
||||
and ensure "Debug executable" is checked in the "Info" tab.
|
||||
''');
|
||||
}
|
||||
} on XmlException catch (exception) {
|
||||
_logger.printError('Failed to parse ${schemeFile.path}: $exception');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
|
||||
@@ -12,7 +12,7 @@ class XcodeProjectObjectVersionMigration extends ProjectMigrator {
|
||||
XcodeBasedProject project,
|
||||
super.logger,
|
||||
) : _xcodeProjectInfoFile = project.xcodeProjectInfoFile,
|
||||
_xcodeProjectSchemeFile = project.xcodeProjectSchemeFile;
|
||||
_xcodeProjectSchemeFile = project.xcodeProjectSchemeFile();
|
||||
|
||||
final File _xcodeProjectInfoFile;
|
||||
final File _xcodeProjectSchemeFile;
|
||||
|
||||
@@ -68,8 +68,10 @@ abstract class XcodeBasedProject extends FlutterProjectPlatform {
|
||||
File get xcodeProjectInfoFile => xcodeProject.childFile('project.pbxproj');
|
||||
|
||||
/// The 'Runner.xcscheme' file of [xcodeProject].
|
||||
File get xcodeProjectSchemeFile =>
|
||||
xcodeProject.childDirectory('xcshareddata').childDirectory('xcschemes').childFile('Runner.xcscheme');
|
||||
File xcodeProjectSchemeFile({String? scheme}) {
|
||||
final String schemeName = scheme ?? 'Runner';
|
||||
return xcodeProject.childDirectory('xcshareddata').childDirectory('xcschemes').childFile('$schemeName.xcscheme');
|
||||
}
|
||||
|
||||
File get xcodeProjectWorkspaceData =>
|
||||
xcodeProject
|
||||
|
||||
Reference in New Issue
Block a user