How to import iOS native framework into Flutter? - 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

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.

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.

Related

No podspec found for `package` when adding iOS project to existing Ionic 5 project

I built a Capacitor plugin for Ionic and Capacitor and published it to NPM - call it test1. I then use it in my Ionic 5 project and successfully add a new Android project via:
ionic build
ionic cap add android
ionic cap sync
Tested it and it works. I then try and add an iOS via:
ionic build
ionic cap add ios
I then get the following error:
`[!] No podspec found for `Test1` in `../../node_modules/test1```
And it fails. I can't figure out why as there is a Test1Plugin.podspec file in the root with relevant dependencies and an ios/Podfile with relevant dependencies. I also ensure both files are published to npm.
I tried changing the name of the .podspec file to Test1.podspec but it's the exact same issue.
I'm pretty stumped and hoping someone has some pointers as i've been on this for a while and tried everything.

Flutter - Cannot find package in .pub-cache reference

I am trying to use tflite_flutter plugin for running a custom ml function from a tflite model. It is working fine on android but for the iOS setup, it requires us to add TensorFlowLiteC.framework on ~/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-<plugin-version>/ios/ folder but I cannot find this folder no matter what I do. It is not just because it is hidden, the tflite_flutter-<plugin-version> folder is not there at all.
I tried:
Adding dependency directly from git.
tflite_flutter:
git:
url: git://github.com/am15h/tflite_flutter_plugin.git
ref: v0.9.0
Running
flutter pub cache repair
flutter pub cache add tflite_flutter
Help would be much appreciated.
use_frameworks!
pod 'TensorFlowLiteSwift'
followed by running pod install in your ios folder.
From official doc
https://www.tensorflow.org/lite/guide/ios
As a developer, you are not bound to using flutter packages only. You can directly add dependencies to your podfile or build.gradle as well.
You'll find your package in ~/development/tools/flutter/.pub-cache/hosted/pub.dartlang.org/

How do you integrate a flutter plugin into an existing flutter project?

I want to install a simple audio recorder which will record a user’s voice. I know I can find plugins on PubDev, however I have difficulty in integrating them into my Flutter project. I have installed ‘audio_recorder 1.0.2. in a new dart file as part of ‘lib’. I don’t know how to integrate this file into the flutter project. I have tried to a button in another dart file which when pressed would take the user to that file, without succes. ‘This class is not a widget’ is the message I get. The ‘GitHub’ version has the errors ‘undefined class’, ‘LocalFileSystem isn’t defined for the type ‘AudioRecorder’. The example version (why this difference?) has quite a few errors after installation. Dependencies and imports are ok. When I install audio_recorder 1.0.2 inside the project via ‘Dart packages’ I get a lot of errors. I have successfully installed an audio recorder in another android app. I would like some help in how to integrate plugins in a flutter project.
The plugins have instructions on how to install it. Got to your pubspec.yaml-file and put it under dependencies.
Make sure that you add your dependency to pubspec.yaml like this:
dependencies:
audio_recorder: ^1.0.2
After that make sure to type "flutter pub get" in console.
Go on a specified file in which you want to use Your dependency and import it like this:
import 'package:audio_recorder/audio_recorder.dart';

How to use cloud_firestore in flutter for web and android?

I have a Flutter app which works on Android as expected but if I want to compile it for Web I get an error.
It has to do something with the dependency cloud_firestore. If I use the dependency firebase it works fine on the web but on android now not..
This is the error message I get using cloud_firestore (compiling for web):
Skipping compiling pay_balance|lib/main_web_entrypoint.dart with ddc because some of its
transitive libraries have sdk dependencies that not supported on this platform:
firebase_core|lib/firebase_core.dart
https://github.com/dart-lang/build/blob/master/docs/faq.md#how-can-i-resolve-skipped-compiling-warnings
Can anybody help me? Maybe with another dependency for firestore (I did not find others which are working on web and android)..
Edit: I have used the firebase-dart plugin for web!! -> Only works on the web but not in android for me -> I need something for both at the same time!!
Or is there a Way I can use both packages without getting a compling error for the web when I import cloud_firestore?
If you want to use Firebase on Web and Mobile you have to get creative. I created the fb_auth plugin that uses the Mobile SDK firebase_auth on iOS and Android and the firebase package on web. This will give you a single plugin for auth.
https://pub.dev/packages/fb_auth
Im working on firstore and storage but they are not ready yet.
I have also created an article on how to do this with flutter:
https://medium.com/#rody.davis.jr/how-to-build-a-native-cross-platform-project-with-flutter-372b9e4b504f
You have to use dynamic imports so that at compile time it tree shakes what it doesn't need and will not throw an error.
Currently this is the only way to officially use both plugins in the same project.
EDIT: cloud_firestore now added
Two of the FutterFire plugins are now supported for web. FlutterFire plugins supporting web firebase_auth and firebase_core
cloud_firestore is now also supported

In flutter when I am trying to run project it is giving error

Pease help me!, I am new to flutter I am importing a project and when I try to run it is giving exception
/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:9: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
^
symbol: class ActivityCompat
location: package android.support.v4.app
My project is already compatible with androidX, I have tried package get and upgrade package but nothing happens, I have got the similar problem
When you migrate a flutter app to AndroidX, all the plugins the app depends on should also support AndroidX else your app build will fail and this is what is happening here.
Even though you have migrated your project to AndroidX, the simple-permissions plugin has not been migrated to AndroidX yet and this is what is causing the issue.
Below are the options you have in this case -
1. User the permission_handler plugin instead of simple-permissions.
The permission_handler plugin is a much more frequently updated plugin which has already been migrated to AndroidX. Here is the link to the plugin.
2. Migrate simple-permissions to AndroidX yourself
If you strictly want to use simple-permissions, you can clone the git repo and manually migrate the plugin to AndroidX and use the plugin via git url inside your pubspec.yaml. Details for migrating plugins to AndroidX can be found here.
You can use the plugin from git url in the following way inside you pubspec.yaml
dependencies:
plugin1:
git:
url: git://github.com/flutter/plugin1.git
//Your repo url goes in place of this url
3. Avoid using AndroidX altogether in you app.
You can force your app to use the older support libraries if you do not wish to perform the above two steps, but by doing this you will need to downgrade all your plugins to versions which do not use AndroidX, which is not the ideal solution.
More about this here.
Hope this helps!