flutter插件开发,踩坑过程

一、flutter插件创建

这个简单带过,
打开Android Studio ->New Flutter Project ->选择Plugin并设置其他相关参数->Finish->等待创建。。。


31645696492_.pic.jpg

41645696492_.pic.jpg

51645696492_.pic.jpg

二、添加原生的framework

说下业务要求:公司要求网络请求,使用我们原生自己封装的库(swift封装),而不使用flutter自带的,就开发个插件(好方便后面公司其他项目用)

1.引入过程见我的另一篇文章

新建flutter插件时,引用swift SDK

2.引入带另一个密码键盘时,出现如下错误

--"vtable for __cxxabiv1::__si_class_type_info", referenced from:
错误日志

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)
静态库中采用ObjectC++或者C、C++实现,遇到这样的问题看看是不是配置不对, 需要保证工程中至少有一个.mm后缀的源文件,或在工程属性中指定编译方式。
注意:(这里的工程是插件里面的pod里面的代码工程,不是runner项目工程,因为最后我们完成的插件里面不会有example的代码工程示例)

371645705031_.pic.jpg

修改方法如下:
1 可以将任意一个.m后缀的文件改名为.mm
2 在 Xcode的 Target -> Build Settings -> Apple LLVM 8.0 - Language -> Compile Sources As修改为"Objective-C++

三、添加原生.a静态库

注意:如果.a静态库有特殊的target配置,而这里没有配置,就会出现一个神奇的现象,在项目工程或者新创建的原生工程.a静态库相关功能运行正常,但是在插件工程里面不行,这是因为在项目工程会自动引入相关设置,插件这边需要自己手动配置(个人在这里耗费几个小时,本来以为库的问题,-_-||)

主要配置如下
 #要暴露的头文件的路径,插件中可引用,多个位置头文件,用逗号隔开
  s.source_files = 'Classes/**/*','Frameworks/iSecurity/include/*.h'
  #公共头文件,构建库时,这些头文件将出现在构建目录中,如果没有指定公共头文件,那么source_files中的所有头文件都被认为是公共的
  s.public_header_files = 'Classes/**/*.h'
  #静态库.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',
    
    #如果静态库.a有特殊的target配置,需要写到这里,
    'ENABLE_BITCODE' => 'NO',
       'OTHER_CFLAGS' => '$(inherited) $(ALGORITHMS)',
       'OTHER_LDFLAGS' => '$(inherited) -ObjC',
  }
391645708132_.pic.jpg
401645708246_.pic.jpg
411645708354_.pic.jpg

你可能感兴趣的:(flutter插件开发,踩坑过程)