[iOS] specify minimum os version for native asset frameworks (#148504)

Fixes https://github.com/flutter/flutter/issues/148501
This commit is contained in:
Matej Knopp 2024-05-21 18:16:08 +02:00 committed by GitHub
parent e6fa865581
commit 454dd7e29c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 76 additions and 8 deletions

View File

@ -230,7 +230,9 @@ Future<void> _copyNativeAssetsIOS(
}
await lipoDylibs(dylibFile, sources);
await setInstallNameDylib(dylibFile);
await createInfoPlist(targetUri.pathSegments.last, frameworkDir);
// TODO(knopp): Wire the value once there is a way to configure that in the hook.
// https://github.com/dart-lang/native/issues/1133
await createInfoPlist(targetUri.pathSegments.last, frameworkDir, minimumIOSVersion: '12.0');
await codesignDylib(codesignIdentity, buildMode, frameworkDir);
}
globals.logger.printTrace('Copying native assets done.');

View File

@ -18,10 +18,13 @@ import '../../../globals.dart' as globals;
/// The framework must be named [name].framework and the dylib [name].
Future<void> createInfoPlist(
String name,
Directory target,
) async {
Directory target, {
String? minimumIOSVersion,
}) async {
final File infoPlistFile = target.childFile('Info.plist');
await infoPlistFile.writeAsString('''
final String bundleIdentifier = 'io.flutter.flutter.native_assets.$name'.replaceAll('_', '-');
await infoPlistFile.writeAsString(<String>[
'''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@ -31,7 +34,7 @@ Future<void> createInfoPlist(
<key>CFBundleExecutable</key>
<string>$name</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.native_assets.$name</string>
<string>$bundleIdentifier</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
@ -44,9 +47,16 @@ Future<void> createInfoPlist(
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
''',
if (minimumIOSVersion != null)
'''
<key>MinimumOSVersion</key>
<string>$minimumIOSVersion</string>
''',
'''
</dict>
</plist>
''');
</plist>'''
].join());
}
/// Combines dylibs from [sources] into a fat binary at [targetFullPath].

View File

@ -345,6 +345,32 @@ void expectDylibIsBundledMacOS(Directory appDirectory, String buildMode) {
final Link dylibLink = frameworkDir.childLink(frameworkName);
expect(dylibLink, exists);
expect(dylibLink.resolveSymbolicLinksSync(), dylibFile.path);
final String infoPlist = resourcesDir.childFile('Info.plist').readAsStringSync();
expect(infoPlist, '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>package_with_native_assets</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.native-assets.package-with-native-assets</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>package_with_native_assets</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
</dict>
</plist>''');
}
void expectDylibIsBundledIos(Directory appDirectory, String buildMode) {
@ -357,6 +383,36 @@ void expectDylibIsBundledIos(Directory appDirectory, String buildMode) {
.childDirectory('$frameworkName.framework')
.childFile(frameworkName);
expect(dylib, exists);
final String infoPlist = frameworksFolder
.childDirectory('$frameworkName.framework')
.childFile('Info.plist').readAsStringSync();
expect(infoPlist, '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>package_with_native_assets</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.native-assets.package-with-native-assets</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>package_with_native_assets</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>12.0</string>
</dict>
</plist>''');
}
/// Checks that dylibs are bundled.