Flutter project custom plug-in iOS platform reference. A pits encountered by static libraries

Description

In flutter development, some third-party plug-ins cannot meet the development needs of the project, and cannot avoid writing custom plug-ins by yourself. How to write custom plug-ins will not be described in detail here. Today, I will mainly summarize the custom plug-in iOS platform reference.a Problems encountered by static libraries.

.podspec file

#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
  s.name             = 'flutter_bt_printer'
  s.version          = '0.0.2'
  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 protected]' }
  s.source           = {
    
     :path => '.' }
  s.source_files = 'Classes/**/*'
  s.vendored_libraries = 'Classes/**/*.a'
  s.public_header_files = 'Classes/**/*.h'
  s.dependency 'Flutter'
  s.ios.deployment_target = '8.0'
end

1. Use third-party libraries (.a files)

s.dependency 'AFNetworking'

2. Refer to the third party static library (.a file)

s.vendored_libraries = 'Classes/xxx.a'

3. When we run, the following error will be reported

ld: library not found for -lxxx
clang: error: linker command failed with exit code 1 (use -v to see invocation)

At this time, you need to delete the corresponding plug-in under the pods of the flutter main project (to find the plug-in corresponding to the reference .a), the -l "XXX" option in the TARGETS–>Build Settings->Other Linker Flags list, and then run it or report a warning Report an error, the content is as follows:

Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_LPAPI", referenced from:
   objc-class-ref in Printermanager.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It shows that the Printermanager file refers to the header file of xxx.a.
At this time, we need TARGETS->Build Phases->Compile Sources to delete xxx.a. Add the newly deleted xxx.a file in another option Link Binary With Libraries at the same level of Compile Sources.

4. Other Linker Flags configuration

Also, according to the prompt of referencing the .a static library, whether to add other flags such as -ObjC or -all_load in the TARGETS->Build Settings->Other Linker Flags list of the plugin.

5. Run

Finally run, if it is unsuccessful or if the above steps go wrong, you can use pod install to reset the settings.

Guess you like

Origin blog.csdn.net/gjm_123/article/details/103689082