具體如何創(chuàng)建插件依賴插件申窘,可參考閑魚技術
現在有一個調用阿里云上傳圖片的插件alioss丢习,打開文件夾其中有個目錄是ios,仔細查看有個alioss.podspec文件酪呻,用CocaPods創(chuàng)建過自己庫的同學應該不陌生羞迷,文件內容如下:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'alioss'
s.version = '0.0.1'
s.summary = 'A new Flutter plugin.'
s.description = <<-DESC
A new Flutter plugin.
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 = '8.0'
end
1.引用阿里三方庫我們在倒數第二行添加界轩。
s.dependency 'AliyunOSSiOS'
這樣我們就引用了阿里的pod庫了,封裝好相關的上傳代碼衔瓮,到flutter主工程下的ios目錄下pod install 完成后浊猾,就可以測試上傳文件的代碼了。
2热鞍、引用三方靜態(tài)庫(.a文件)我們再添加一行葫慎。(在另一個插件里有個連接打印機功能衔彻,就不再重復.podspec文件了)
s.vendored_libraries = 'Classes/LPAPI/CAR_PRINT.a'
然后把靜態(tài)庫放在相應的文件夾路徑下,同樣使用pod install重新構建工程偷办,run下會報警告報錯艰额,內容如下:
Warning: no rule to process file '/Users/xxx/development/FlutterPlugin/xxx/ios/Classes/LPAPI/CAR_PRINT.a' of type archive.ar for architecture armv7
Warning: no rule to process file '/Users/xxx/development/FlutterPlugin/xxx/ios/Classes/LPAPI/CAR_PRINT.a' of type archive.ar for architecture arm64
ld: library not found for -lCAR_PRINT
clang: error: linker command failed with exit code 1 (use -v to see invocation)
這時候需要刪除 flutter主工程的pods下對應的插件(千萬要找到引用.a對應的插件)的TARGETS-->Build Settings->Other Linker Flags列表中的-l"CAR_PRINT" 選項,再run一下還是報警告報錯椒涯,內容如下:
Warning: no rule to process file '/Users/xxx/development/FlutterPlugin/xxx/ios/Classes/LPAPI/CAR_PRINT.a' of type archive.ar for architecture armv7
Warning: no rule to process file '/Users/xxx/development/FlutterPlugin/xxx/ios/Classes/LPAPI/CAR_PRINT.a' of type archive.ar for architecture arm64
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_LPAPI", referenced from:
objc-class-ref in PrinterViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
說明PrinterViewController文件引用了CAR_PRINT.a的頭文件柄沮。
這時候我們需要TARGETS-->Build Phases-->Compile Sources 刪除CAR_PRINT.a文件,再在Compile Sources同級的另一個選項Link Binary With Libraries 里添加剛剛刪除的CAR_PRINT.a文件废岂。
最后再run一下祖搓,控制臺顯示內容如下:
Launching lib/main.dart on iPhone 8 in debug mode...
Xcode build done. 51.9s
最后我們還要根據引用.a靜態(tài)庫的提示是否要在插件的TARGETS-->Build Settings->Other Linker Flags列表中加入-ObjC或-all_load等其他flag.
如果上述步驟出錯可以使用pod install重置設置選項,還有xcode還是無法運行flutter主工程的泪喊,我用的是vscode和vscode flutter插件來運行棕硫。
3髓涯、引用三方動態(tài)庫Framework的坑還沒試過袒啼,最后的資料里有提到。
最后我們來一張運行圖紀念一下纬纪。