将IOS SDK库导入Flutter插件

时间:2019-07-17 01:05:23

标签: flutter flutter-plugin flutter-platform-channel

摘要: 我正在构建一个Flutter插件,可用于我正在开发的多个项目。我没有编写自定义平台特定代码的经验。

我无法将用于IOS * .Framework和* -Resources.bundle的SDK库导入我的插件。

我已经尝试了https://github.com/flutter/flutter/issues/17978

中的解决方案

此外,我尝试清理并重新构建应用程序但未成功,并尝试清理并重新构建示例应用程序但未成功 我收到以下错误:

*。podspec:

Pod::Spec.new do |s|
  s.name             = 'plugin_name'
  s.version          = '0.0.1'
  s.summary          = 'A new flutter plugin project.'
  s.description      = <<-DESC
A new flutter plugin project.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => 'email@example.com' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'

  s.ios.deployment_target = '9.0'
end


Pod::Spec.new do |spec|
  spec.name         = "plugin_name"
  spec.version      = "2.3.7"
  spec.summary      = "SDK"
  spec.homepage     = "https://hkhars.com"
  spec.author       = "Hussain Alkhars"
  spec.license          = { :file => '../LICENSE' }
  spec.source           = { :path => '.' }
  spec.ios.deployment_target  = '9.0'
  spec.preserve_paths = 'IOSFLUTTERSDK.framework'
  spec.xcconfig = { 'OTHER_LDFLAGS' => '-framework IOSFLUTTERSDK' }
  spec.vendored_frameworks = 'IOSFLUTTERSDK.framework'
  spec.public_header_files = "IOSFLUTTERSDK.framework/Headers/*.h"
  spec.resource_bundle = { 'IOSFLUTTERSDK-Resources' => './*' }
end

尝试使用flutter build ios --no-codesign

构建时出错
fatal error: 'plugin_name/PluginNamePlugin.h' file not found
    #import <plugin_name/PluginNamePlugin.h>```

1 个答案:

答案 0 :(得分:0)

您已经破坏了Podspec文件。 Pod::Spec.new do |s|...开头应该只有一个部分。如果您想在链接的Github问题中尝试这种方法,您的Podspec文件应如下所示:

Pod::Spec.new do |s|
  s.name             = 'plugin_name'
  s.version          = '0.0.1'
  s.summary          = 'A new flutter plugin project.'
  s.description      = <<-DESC
A new flutter plugin project.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => 'email@example.com' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'
  s.ios.deployment_target = '9.0'
  s.preserve_paths = 'IOSFLUTTERSDK.framework'
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework IOSFLUTTERSDK' }
  s.vendored_frameworks = 'IOSFLUTTERSDK.framework'
  s.resource_bundle = { 'IOSFLUTTERSDK-Resources' => './*' }
end

但是,我之前尝试过但没有成功-我需要通过打开项目来通过Xcode手动链接所有内容:

open example/ios/Runner.xcworksapce

点击顶部的“ Runner”项目,然后点击右侧的“ Build Phases”项(如果未显示“ Build Phases”,请确保已选中左侧的文件夹图标,并且您单击了中间面板中的Runner Target ,而不是Runner项目。

enter image description here

找到“使用库链接二进制文件”面板,然后单击“ +”按钮:

enter image description here

选择您的.framework文件,然后单击“完成”。在“嵌入式​​框架”下重复相同的操作。

我不确定100%,但是我认为您可以在“复制捆绑资源”下进行相同的操作。