一曙求、flutter插件創(chuàng)建
這個(gè)簡(jiǎn)單帶過(guò)与帆,
打開Android Studio ->New Flutter Project ->選擇Plugin并設(shè)置其他相關(guān)參數(shù)->Finish->等待創(chuàng)建卖词。巩那。。
二此蜈、添加原生的framework
說(shuō)下業(yè)務(wù)要求:公司要求網(wǎng)絡(luò)請(qǐng)求即横,使用我們?cè)约悍庋b的庫(kù)(swift封裝),而不使用flutter自帶的裆赵,就開發(fā)個(gè)插件(好方便后面公司其他項(xiàng)目用)
1.引入過(guò)程見(jiàn)我的另一篇文章
新建flutter插件時(shí)东囚,引用swift SDK
2.引入帶另一個(gè)密碼鍵盤時(shí),出現(xiàn)如下錯(cuò)誤
--"vtable for __cxxabiv1::__si_class_type_info", referenced from:
錯(cuò)誤日志
Undefined symbols for architecture arm64:
"vtable for __cxxabiv1::__si_class_type_info", referenced from:
typeinfo for Kernel in libTalkingData.a(svm.o)
typeinfo for Solver_NU in libTalkingData.a(svm.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"___cxa_pure_virtual", referenced from:
vtable for Kernel in libTalkingData.a(svm.o)
"vtable for __cxxabiv1::__class_type_info", referenced from:
typeinfo for QMatrix in libTalkingData.a(svm.o)
typeinfo for Solver in libTalkingData.a(svm.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator delete(void)", referenced from:
Kernel::~Kernel() in libTalkingData.a(svm.o)
Solver::~Solver() in libTalkingData.a(svm.o)
Solver_NU::~Solver_NU() in libTalkingData.a(svm.o)
"operator delete", referenced from:
Kernel::~Kernel() in libTalkingData.a(svm.o)
Solver::Solve(int, QMatrix const&, double const, signed char const, double, double, double, double, Solver::SolutionInfo, int) in libTalkingData.a(svm.o)
"operator new[](unsigned long)", referenced from:
Kernel::Kernel(int, svm_node const, svm_parameter const&) in libTalkingData.a(svm.o)
Solver::Solve(int, QMatrix const&, double const, signed char const, double, double, double, double, Solver::SolutionInfo*, int) in libTalkingData.a(svm.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
靜態(tài)庫(kù)中采用ObjectC++或者C战授、C++實(shí)現(xiàn)页藻,遇到這樣的問(wèn)題看看是不是配置不對(duì)桨嫁, 需要保證工程中至少有一個(gè).mm后綴的源文件,或在工程屬性中指定編譯方式份帐。
注意:(這里的工程是插件里面的pod里面的代碼工程璃吧,不是runner項(xiàng)目工程,因?yàn)樽詈笪覀兺瓿傻牟寮锩娌粫?huì)有example的代碼工程示例)
修改方法如下:
1 可以將任意一個(gè).m后綴的文件改名為.mm
2 在 Xcode的 Target -> Build Settings -> Apple LLVM 8.0 - Language -> Compile Sources As修改為"Objective-C++
三废境、添加原生.a靜態(tài)庫(kù)
注意:如果.a靜態(tài)庫(kù)有特殊的target配置肚逸,而這里沒(méi)有配置,就會(huì)出現(xiàn)一個(gè)神奇的現(xiàn)象彬坏,在項(xiàng)目工程或者新創(chuàng)建的原生工程.a靜態(tài)庫(kù)相關(guān)功能運(yùn)行正常朦促,但是在插件工程里面不行,這是因?yàn)樵陧?xiàng)目工程會(huì)自動(dòng)引入相關(guān)設(shè)置栓始,插件這邊需要自己手動(dòng)配置(個(gè)人在這里耗費(fèi)幾個(gè)小時(shí)务冕,本來(lái)以為庫(kù)的問(wèn)題,-_-||)
主要配置如下
#要暴露的頭文件的路徑幻赚,插件中可引用,多個(gè)位置頭文件禀忆,用逗號(hào)隔開
s.source_files = 'Classes/**/*','Frameworks/iSecurity/include/*.h'
#公共頭文件,構(gòu)建庫(kù)時(shí)落恼,這些頭文件將出現(xiàn)在構(gòu)建目錄中箩退,如果沒(méi)有指定公共頭文件,那么source_files中的所有頭文件都被認(rèn)為是公共的
s.public_header_files = 'Classes/**/*.h'
#靜態(tài)庫(kù).a的路徑
s.vendored_libraries = 'Frameworks/iSecurity/**/*.a'
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386',
#如果靜態(tài)庫(kù).a有特殊的target配置佳谦,需要寫到這里戴涝,
'ENABLE_BITCODE' => 'NO',
'OTHER_CFLAGS' => '$(inherited) $(ALGORITHMS)',
'OTHER_LDFLAGS' => '$(inherited) -ObjC',
}