diff --git a/packages/flutter_tools/lib/src/ios/xcodeproj.dart b/packages/flutter_tools/lib/src/ios/xcodeproj.dart index f11dad62b4..7d00695159 100644 --- a/packages/flutter_tools/lib/src/ios/xcodeproj.dart +++ b/packages/flutter_tools/lib/src/ios/xcodeproj.dart @@ -80,6 +80,15 @@ void updateGeneratedXcodeProperties({ if (artifacts is LocalEngineArtifacts) { final LocalEngineArtifacts localEngineArtifacts = artifacts; localsBuffer.writeln('LOCAL_ENGINE=${localEngineArtifacts.engineOutPath}'); + + // Tell Xcode not to build universal binaries for local engines, which are + // single-architecture. + // + // NOTE: this assumes that local engine binary paths are consistent with + // the conventions uses in the engine: 32-bit iOS engines are built to + // paths ending in _arm, 64-bit builds are not. + final String arch = localEngineArtifacts.engineOutPath.endsWith('_arm') ? 'armv7' : 'arm64'; + localsBuffer.writeln('ARCHS=$arch'); } if (previewDart2) { diff --git a/packages/flutter_tools/test/ios/xcodeproj_test.dart b/packages/flutter_tools/test/ios/xcodeproj_test.dart index 426c9c4c8d..dd75f93988 100644 --- a/packages/flutter_tools/test/ios/xcodeproj_test.dart +++ b/packages/flutter_tools/test/ios/xcodeproj_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:file/memory.dart'; +import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/build_info.dart'; @@ -252,11 +253,76 @@ Information about project "Runner": expect(info.buildConfigurationFor(const BuildInfo(BuildMode.release, 'Paid'), 'Paid'), null); }); }); + + group('updateGeneratedXcodeProperties', () { + MockLocalEngineArtifacts mockArtifacts; + MockProcessManager mockProcessManager; + FakePlatform macOS; + FileSystem fs; + + setUp(() { + fs = new MemoryFileSystem(); + mockArtifacts = new MockLocalEngineArtifacts(); + mockProcessManager = new MockProcessManager(); + macOS = fakePlatform('macos'); + fs.file(xcodebuild).createSync(recursive: true); + }); + + void testUsingOsxContext(String description, dynamic testMethod()) { + testUsingContext(description, testMethod, overrides: { + Artifacts: () => mockArtifacts, + ProcessManager: () => mockProcessManager, + Platform: () => macOS, + FileSystem: () => fs, + }); + } + + testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () { + when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, any)).thenReturn('engine'); + when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile_arm')); + const BuildInfo buildInfo = const BuildInfo(BuildMode.debug, null, + previewDart2: true, + targetPlatform: TargetPlatform.ios, + ); + updateGeneratedXcodeProperties( + projectPath: 'path/to/project', + buildInfo: buildInfo, + previewDart2: true, + ); + + final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig'); + expect(config.existsSync(), isTrue); + + final String contents = config.readAsStringSync(); + expect(contents.contains('ARCHS=armv7'), isTrue); + }); + + testUsingOsxContext('sets ARCHS=armv7 when armv7 local engine is set', () { + when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, any)).thenReturn('engine'); + when(mockArtifacts.engineOutPath).thenReturn(fs.path.join('out', 'ios_profile')); + const BuildInfo buildInfo = const BuildInfo(BuildMode.debug, null, + previewDart2: true, + targetPlatform: TargetPlatform.ios, + ); + updateGeneratedXcodeProperties( + projectPath: 'path/to/project', + buildInfo: buildInfo, + previewDart2: true, + ); + + final File config = fs.file('path/to/project/ios/Flutter/Generated.xcconfig'); + expect(config.existsSync(), isTrue); + + final String contents = config.readAsStringSync(); + expect(contents.contains('ARCHS=arm64'), isTrue); + }); + }); } Platform fakePlatform(String name) { return new FakePlatform.fromPlatform(const LocalPlatform())..operatingSystem = name; } +class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {} class MockProcessManager extends Mock implements ProcessManager {} class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter { }