Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import iOS native framework into Flutter?

Tags:

flutter

I want to contribute in this Flutter_blue plugin project adding the functionalities for native iOS using Objective C framework CoreBluetooth. How do I import the framework in to the library so I can start using its APIs?

Update:

CoreBluetooth is not suitable for Flutter project, because it's not a cocoapod dependency. So what I did what, go to cocopods website and look for other bluetooth dependencies from there. You can also find instructions of how to install a dependency there. For me, I made added pod <depdencyname> to <plugin-project>/example/ios/Podfile in the plugin project. Then added dependency: <dependencyname> to the in <plugin-project>/ios/pubspec

like image 379
grepLines Avatar asked Jan 25 '18 05:01

grepLines


People also ask

Can I use native code in Flutter?

Flutter mobile and desktop apps can use the dart:ffi library to call native C APIs. FFI stands for foreign function interface. Other terms for similar functionality include native interface and language bindings.


2 Answers

I had the same problem for a few time and found a solution by adding this lines to your podspec file at your iOS/ folder in your plugin dir:

  s.preserve_paths = 'yourframework.framework'
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework yourframework' }
  s.vendored_frameworks = 'yourframework.framework'

Then, on your Flutter project, in the iOS folder, just run pod update on terminal so it can fetch the new dependencies.

You can find the full issue open by me with this problem here.

like image 150
Miguel Ruivo Avatar answered Sep 21 '22 02:09

Miguel Ruivo


If you're looking to add a CocoaPod dependency to the iOS "half" of a Flutter plugin, I believe the correct way to do so is to update the podspec file in the /ios folder of the plugin source. I recently did some work on the AdMob plugin, for example, and its podspec lists the SDKs for Firebase and Google Mobile Ads:

https://github.com/flutter/plugins/blob/master/packages/firebase_admob/ios/firebase_admob.podspec

And that's how they get included in the build.

like image 42
RedBrogdon Avatar answered Sep 18 '22 02:09

RedBrogdon