Unverified Commit 08128cb2 authored by Sarah Zakarias's avatar Sarah Zakarias Committed by GitHub

Upgrade project.pbxproj to include flutter_assets (#13011)

parent 3af6b9cb
......@@ -206,6 +206,9 @@ Future<XcodeBuildResult> 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<Map<String, String>> services, File ma
final Map<String, dynamic> json = <String, dynamic>{ 'services' : jsonServices };
manifest.writeAsStringSync(JSON.encode(json), mode: FileMode.WRITE, flush: true);
}
Future<bool> upgradePbxProjWithFlutterAssets(String app) async {
final File xcodeProjectFile = fs.file(fs.path.join('ios', 'Runner.xcodeproj',
'project.pbxproj'));
assert(await xcodeProjectFile.exists());
final List<String> 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 = "<group>"; };';
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment