diff --git a/dev/devicelab/bin/tasks/module_test_ios.dart b/dev/devicelab/bin/tasks/module_test_ios.dart index 81f69bf7bc..85cb3b42b7 100644 --- a/dev/devicelab/bin/tasks/module_test_ios.dart +++ b/dev/devicelab/bin/tasks/module_test_ios.dart @@ -246,6 +246,9 @@ dependencies: final Directory objectiveCBuildDirectory = Directory(path.join(tempDir.path, 'build-objc')); section('Build iOS Objective-C host app'); + + final File dummyAppFramework = File(path.join(projectDir.path, '.ios', 'Flutter', 'App.framework', 'App')); + checkFileNotExists(dummyAppFramework.path); await inDirectory(objectiveCHostApp, () async { await exec( 'pod', @@ -267,6 +270,14 @@ dependencies: throw TaskResult.failure('Building host app Podfile.lock does not contain expected pods'); } + // Just running "pod install" should create a fake App.framework so CocoaPods recognizes + // it as a framework that needs to be embedded, before Flutter actually creates it. + checkFileExists(dummyAppFramework.path); + final String? version = await minPhoneOSVersion(dummyAppFramework.path); + if (version != '9.0') { + throw TaskResult.failure('Minimum version set to $version, expected 9.0'); + } + await exec( 'xcodebuild', [ diff --git a/dev/devicelab/lib/framework/ios.dart b/dev/devicelab/lib/framework/ios.dart index e0691fcfa3..2a384edbe2 100644 --- a/dev/devicelab/lib/framework/ios.dart +++ b/dev/devicelab/lib/framework/ios.dart @@ -16,6 +16,37 @@ Future fileType(String pathToBinary) { return eval('file', [pathToBinary]); } +Future minPhoneOSVersion(String pathToBinary) async { + final String loadCommands = await eval('otool', [ + '-l', + '-arch', + 'arm64', + pathToBinary, + ]); + if (!loadCommands.contains('LC_VERSION_MIN_IPHONEOS')) { + return null; + } + + String? minVersion; + // Load command 7 + // cmd LC_VERSION_MIN_IPHONEOS + // cmdsize 16 + // version 9.0 + // sdk 15.2 + // ... + final List lines = LineSplitter.split(loadCommands).toList(); + lines.asMap().forEach((int index, String line) { + if (line.contains('LC_VERSION_MIN_IPHONEOS') && lines.length - index - 1 > 3) { + final String versionLine = lines + .skip(index - 1) + .take(4).last; + final RegExp versionRegex = RegExp(r'\s*version\s*(\S*)'); + minVersion = versionRegex.firstMatch(versionLine)?.group(1); + } + }); + return minVersion; +} + Future containsBitcode(String pathToBinary) async { // See: https://stackoverflow.com/questions/32755775/how-to-check-a-static-library-is-built-contain-bitcode final String loadCommands = await eval('otool', [ diff --git a/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl b/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl index 2dbaaaa94c..3b065203dd 100644 --- a/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl +++ b/packages/flutter_tools/templates/module/ios/library/Flutter.tmpl/podhelper.rb.tmpl @@ -109,7 +109,8 @@ def install_flutter_application_pod(flutter_application_path) # CocoaPods will not embed the framework on pod install (before any build phases can run) if the dylib does not exist. # Create a dummy dylib. FileUtils.mkdir_p(app_framework_dir) - `echo "static const int Moo = 88;" | xcrun clang -x c -dynamiclib -o "#{app_framework_dylib}" -` + sdk_path = `xcrun --sdk iphoneos --show-sdk-path`.strip + `echo "static const int Moo = 88;" | xcrun clang -x c -arch arm64 -dynamiclib -miphoneos-version-min=9.0 -isysroot "#{sdk_path}" -o "#{app_framework_dylib}" -` end # Keep pod and script phase paths relative so they can be checked into source control.