Solve the problem that <Flutter/Flutter.h> cannot be imported when a pod transitive depends on Flutter (#125610)
  If a pod transitive depends on a pod containing a framework, cocoapods will add the path of the framework to its FRAMEWORK_SEARCH_PATHS. So I modified the relevant logic in podhelper, hoping to be consistent with the behavior of cocoapods. Fixes https://github.com/flutter/flutter/issues/126251.
This commit is contained in:
@@ -9,6 +9,8 @@ Future<void> main() async {
|
||||
await task(combine(<TaskFunction>[
|
||||
PluginTest('ios', <String>['-i', 'objc', '--platforms=ios']).call,
|
||||
PluginTest('ios', <String>['-i', 'swift', '--platforms=ios']).call,
|
||||
// Test that app builds with Flutter as a transitive dependency.
|
||||
PluginTest('ios', <String>['-i', 'objc', '--platforms=ios'], cocoapodsTransitiveFlutterDependency: true).call,
|
||||
// Test that Dart-only plugins are supported.
|
||||
PluginTest('ios', <String>['--platforms=ios'], dartOnlyPlugin: true).call,
|
||||
// Test that shared darwin directories are supported.
|
||||
|
||||
@@ -35,6 +35,7 @@ class PluginTest {
|
||||
this.dartOnlyPlugin = false,
|
||||
this.sharedDarwinSource = false,
|
||||
this.template = 'plugin',
|
||||
this.cocoapodsTransitiveFlutterDependency = false,
|
||||
});
|
||||
|
||||
final String buildTarget;
|
||||
@@ -44,6 +45,7 @@ class PluginTest {
|
||||
final bool dartOnlyPlugin;
|
||||
final bool sharedDarwinSource;
|
||||
final String template;
|
||||
final bool cocoapodsTransitiveFlutterDependency;
|
||||
|
||||
Future<TaskResult> call() async {
|
||||
final Directory tempDir =
|
||||
@@ -80,6 +82,11 @@ class PluginTest {
|
||||
await app.addPlugin('path_provider');
|
||||
section('Build app');
|
||||
await app.build(buildTarget, validateNativeBuildProject: !dartOnlyPlugin);
|
||||
if (cocoapodsTransitiveFlutterDependency) {
|
||||
section('Test app with Flutter as a transitive CocoaPods dependency');
|
||||
await app.addCocoapodsTransitiveFlutterDependency();
|
||||
await app.build(buildTarget, validateNativeBuildProject: !dartOnlyPlugin);
|
||||
}
|
||||
if (runFlutterTest) {
|
||||
section('Test app');
|
||||
await app.runFlutterTest();
|
||||
@@ -361,6 +368,57 @@ public class $pluginClass: NSObject, FlutterPlugin {
|
||||
return project;
|
||||
}
|
||||
|
||||
/// Creates a Pod that uses a Flutter plugin as a dependency and therefore
|
||||
/// Flutter as a transitive dependency.
|
||||
Future<void> addCocoapodsTransitiveFlutterDependency() async {
|
||||
final String iosDirectoryPath = path.join(rootPath, 'ios');
|
||||
|
||||
final File nativePod = File(path.join(
|
||||
iosDirectoryPath,
|
||||
'NativePod',
|
||||
'NativePod.podspec',
|
||||
));
|
||||
nativePod.createSync(recursive: true);
|
||||
nativePod.writeAsStringSync('''
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'NativePod'
|
||||
s.version = '1.0.0'
|
||||
s.summary = 'A pod to test Flutter as a transitive dependency.'
|
||||
s.homepage = 'https://flutter.dev'
|
||||
s.license = { :type => 'BSD' }
|
||||
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
|
||||
s.source = { :path => '.' }
|
||||
s.source_files = "Classes", "Classes/**/*.{h,m}"
|
||||
s.dependency 'plugintest'
|
||||
end
|
||||
''');
|
||||
|
||||
final File nativePodClass = File(path.join(
|
||||
iosDirectoryPath,
|
||||
'NativePod',
|
||||
'Classes',
|
||||
'NativePodTest.m',
|
||||
));
|
||||
nativePodClass.createSync(recursive: true);
|
||||
nativePodClass.writeAsStringSync('''
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
@interface NativePodTest : NSObject
|
||||
|
||||
@end
|
||||
|
||||
@implementation NativePodTest
|
||||
|
||||
@end
|
||||
''');
|
||||
|
||||
final File podfileFile = File(path.join(iosDirectoryPath, 'Podfile'));
|
||||
final List<String> podfileContents = podfileFile.readAsLinesSync();
|
||||
final int index = podfileContents.indexWhere((String line) => line.contains('flutter_install_all_ios_pods'));
|
||||
podfileContents.insert(index, "pod 'NativePod', :path => 'NativePod'");
|
||||
podfileFile.writeAsStringSync(podfileContents.join('\n'));
|
||||
}
|
||||
|
||||
// Make the platform version artificially low to test that the "deployment
|
||||
// version too low" warning is never emitted.
|
||||
void _reduceDarwinPluginMinimumVersion(String plugin, String target) {
|
||||
|
||||
Reference in New Issue
Block a user