From 08128cb29b28db00c2301f546bc59de33017074a Mon Sep 17 00:00:00 2001 From: Sarah Zakarias Date: Wed, 13 Dec 2017 23:02:10 +0100 Subject: [PATCH] Upgrade project.pbxproj to include flutter_assets (#13011) --- packages/flutter_tools/lib/src/ios/mac.dart | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index eb325082cc..f7b87ffdee 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -206,6 +206,9 @@ Future buildXcodeProject({ bool codesign: true, bool usesTerminalUi: true, }) async { + if (!await upgradePbxProjWithFlutterAssets(app.name)) + return new XcodeBuildResult(success: false); + if (!_checkXcodeVersion()) return new XcodeBuildResult(success: false); @@ -492,3 +495,53 @@ void _copyServiceDefinitionsManifest(List> services, File ma final Map json = { 'services' : jsonServices }; manifest.writeAsStringSync(JSON.encode(json), mode: FileMode.WRITE, flush: true); } + +Future upgradePbxProjWithFlutterAssets(String app) async { + final File xcodeProjectFile = fs.file(fs.path.join('ios', 'Runner.xcodeproj', + 'project.pbxproj')); + assert(await xcodeProjectFile.exists()); + final List lines = await xcodeProjectFile.readAsLines(); + + if (lines.any((String line) => line.contains('path = Flutter/flutter_assets'))) + return true; + + final String l1 = ' 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };'; + final String l2 = ' 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };'; + final String l3 = ' 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; };'; + final String l4 = ' 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };'; + final String l5 = ' 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,'; + final String l6 = ' 2D5378251FAA1A9400D5DBA9 /* flutter_assets */,'; + final String l7 = ' 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,'; + final String l8 = ' 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,'; + + + printStatus("Upgrading project.pbxproj of $app' to include the " + "'flutter_assets' directory"); + + if (!lines.contains(l1) || !lines.contains(l3) || + !lines.contains(l5) || !lines.contains(l7)) { + printError('Automatic upgrade of project.pbxproj failed.'); + printError(' To manually upgrade, open ios/Runner.xcodeproj/project.pbxproj:'); + printError(' Add the following line in the "PBXBuildFile" section'); + printError(l2); + printError(' Add the following line in the "PBXFileReference" section'); + printError(l4); + printError(' Add the following line in the "children" list of the "Flutter" group in the "PBXGroup" section'); + printError(l6); + printError(' Add the following line in the "files" list of "Resources" in the "PBXResourcesBuildPhase" section'); + printError(l8); + return false; + } + + lines.insert(lines.indexOf(l1) + 1, l2); + lines.insert(lines.indexOf(l3) + 1, l4); + lines.insert(lines.indexOf(l5) + 1, l6); + lines.insert(lines.indexOf(l7) + 1, l8); + + // TODO(zarah): Remove lines with 'app.flx' once 'app.flx' is not used anymore. + + final StringBuffer buffer = new StringBuffer(); + lines.forEach(buffer.writeln); + await xcodeProjectFile.writeAsString(buffer.toString()); + return true; +} \ No newline at end of file