Flutter - Cannot find package in .pub-cache reference - flutter

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/

Related

purchases_flutter minimum deployment target error

I am receiving the following error when I compile my FLutter project after adding package:
purchases_flutter: ^4.0.1 to it ....
[!] CocoaPods could not find compatible versions for pod "purchases_flutter":
In Podfile:
purchases_flutter (from .symlinks/plugins/purchases_flutter/ios)
Specs satisfying the purchases_flutter (from .symlinks/plugins/purchases_flutter/ios)
dependency were found, but they required a higher minimum deployment target.
I have checked the Readme in PubDev for this package which says:
minimum targets iOS 9.0+ is required.
However when I look in my PoDFile I have platform :ios, '10.0'. And in Xcode:
Am I missing something here. I haven't seen any other Deployment targets in Xcode or Podfile.
Would really appreciate it, if someone could point me in the correct direction with this.
Many thanks.
I have also tried creating a new Flutter project to test this from the start again and used the terminal commands as suggested below.
I still get the same error... here is a full screen shot of my Android Studio window. Showing the error, my IOS drive and Podfile.
You need to prioritize your dependencies. If the problem is only with this package or plugin, just add it with flutter pub add [dependency name], avoiding directly writing pubspec.yaml It prevents conflict between package versions, automatically finding appropriate version. Then in Podfile top define minimum version. Delete pubspec.lock file, ios/Podfile.lock file and ios/Pods directory. Execute flutter pub get. Enter ios directory via Terminal, execute pod install and try to run application again. If your Mac has apple silicon chip pod install command will be a bit different. Let me know, it worked or not.

Flutter | Error: Couldn't resolve the package

I created a package that is a collection of my own helper classes for faster developing...
The package also included firebase_analytics: which requires a native implementation for each platform i want it to run. Even if i dont wanted to use firebase at all, but still wanted to use my package i was forced to create firebase-config files for the app, because the app crashes if the firebase_analytics package does not find a valid file for the specific platform. To avoid those things i splitted my package in two packages.
The Core-Package: All helper classes that run native dart code
Optional extension: Only the classes that need the firebase implementation
So if i want to use the package without firebase i just have to depend on the core.
If i want to use the firebase variant i could simply depend the firebase package, because the extension package itself depends on the core-package in its own pubspec.yaml file.
PROBLEM: Since i restructured my package like i described, all my apps that depend on it are not building anymore. The console says that all packages that i depend on in my two packages can not be found. This error occures both ways: With firebase & without.
ERROR: (Scroll down for the complete console output)
MY ATTEMPTS:
"flutter clean" & "flutter pub get" in every package and app folder
"flutter pub cache repair"
CORE-PACKAGE Pubspec.yaml:
FIREBASE-Extension Pubspec.yaml:
Plain Console Output:
pastebin.com/m14cbqDV
Thanks for any help!!
I am facing the same issue while i was making a build in Xcode 13.So I had upgraded my flutter version 2.8.0 to 2.10.2 and also removed the version of all firebase dependencies, then the issue was finally solved.
I have faced similar issues and resolved them by removing package versions. Issues like this often arise due to mismatched versions of packages (eg firebase_core, firebase analytics). Please try to remove versions of the firebase packages or the whole packages. (like firebase_analytics :).
Sorry, my bad! As you can see i moved my dependencys to the dev section of my pubspec.yaml. They should be placed in the dependency section.

Could not resolve project :url_launcher_macos

I create new app in flutter and it's work when I run it, but when I add shared_preferences package, I got this error when I run it
Could not determine the dependencies of task ':url_launcher:compileDebugAidl'.
Could not resolve all task dependencies for configuration ':url_launcher:debugCompileClasspath'.
Could not resolve project :url_launcher_macos.
Required by:
project :url_launcher
Unable to find a matching configuration of project :url_launcher_macos:
- None of the consumable configurations have attributes.
Neither package is compatible with mac
I have faced the same problem and i have fixed this with running following command:
flutter pub cache repair
If this is not working then please try the following:
flutter channel stable then run the commands
flutter clean and flutter upgrade
This worked for me
NOTE:- CLOSE THE FLUTTER PROJECT
Go to Flutter sdk path
Enable the view hidden files in Mac by using CTRL + SHIFT + .
Go to .pub-cache
Go to hosted
Go to pub.dartlang.org
delete this folder url_launcher_macos
Open the project and run app

Flutter web cannot use packages from mobile project

A few months ago I made an android application using flutter. The application requires various dependencies such as intl, cached network image, stopper, carousel_slider, etc.
Then right now I want to convert the project to flutter_web. Here are the steps that I did:
clone github web flutter
I run the command "flutter packages pub global activate webdev"
Then I edited pubspec.yaml and I adjusted it to pubspec.yaml in the previous project (android project)
Here is the contents of pubspec.yaml on the web flutter project:
name: flutter_web.examples.hello_world
environment:
  # You must be using Flutter> = 1.5.0 or Dart> = 2.3.0
  sdk: '> = 2.3.0-dev.0.1 <3.0.0'
dependencies:
  flutter_web: any
  flutter_web_ui: any
  stopper: ^ 1.0.1
dev_dependencies:
  build_runner: ^ 1.4.0
  build_web_compilers: ^ 2.0.0
dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web_ui
  provider:
    git:
      url: https://github.com/kevmoo/provider
      ref: flutter_web
When I run 'pub dev', an error occurs while resolving the package stopper. Then I tried to open github from the package stopper (https://github.com/aryzhov/flutter-stopper), after that I checked the files in the lib folder. There I found a file called stopper.dart. It turns out that in the file, still using
 import 'package: flutter / material.dart';
So that makes my pubspec error. Because the code should be replaced with
import 'package: flutter_web / material.dart';
Therefore, I tried to outsmart the problem by removing the dependency stopper on pubspec.yaml, then I created a stopper.dart file manually, then I saved it in the lib/mypackages folder. After that, I import stopper.dart from the lib/mypackages folder (it's no longer through the package).
The package stopper is just one of the packages that I use on my Android project. Actually there are many other packages that have the same problem as the package stopper. The point is I have to create the package files manually, then I change "package: flutter / ..." to "package: flutter_web /" manually, then I can import them.
What I want to ask, is there a more elegant and simple way?
Hi the instruction you are following is from an old repository here. As you can see this is discontinued. You can find the informaiton in the REadme.
Instead you should follow the instructions in this page. Read it once carefully and I would suggest to keep a backup of your main project and work on a copy.
First you will have to enable the flutter-web using flutter config --enable-web.
Then you will have to run flutter create .

How to remove or identify unused packages from flutter to reduce size of the project?

I used some packages that I no longer need in my flutter project, namely the wilddog_auth and wilddog_sync, I can remove the imports from pubspec.yaml file, and my dart files (aka removing import 'package:wilddog_sync/wilddog_sync.dart' etc.) and remove imports in MainActivity.java as well as in Xcode project but I can't purge the unused files installed by flutter, cocoapod and gradle. Now is there a unified command in flutter where I can remove all unused packages at once?
I am pretty sure using flutter clean only removes build folder and using flutter packages get after removing packages from pubspec.yaml doesn't remove packages from cocoapod or gradle either.
For example, after flutter clean and flutter packages get I rebuilt the project:
Launching lib/main.dart on Android SDK built for x86 64 in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
I/FlutterActivityDelegate(11331): onResume setting current activity to this
I/Choreographer(11331): Skipped 107 frames! The application may be doing too much work on its main thread.
D/EGL_emulation(11331): eglMakeCurrent: 0x79f21b4dbec0: ver 2 0 (tinfo 0x79f219b4f160)
I/OpenGLRenderer(11331): Davey! duration=1903ms; Flags=1, IntendedVsync=7544454683637, Vsync=7546238016899, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=7546253803603, AnimationStart=7546253996603, PerformTraversalsStart=7546254171603, DrawStart=7546279222603, SyncQueued=7546288526603, SyncStart=7546295569603, IssueDrawCommandsStart=7546296644603, SwapBuffers=7546334455603, FrameCompleted=7546365204603, DequeueBufferDuration=2892000, QueueBufferDuration=199000,
Syncing files to device Android SDK built for x86 64...
D/ (11331): HostConnection::get() New Host Connection established 0x79f219ab81e0, tid 11383
D/EGL_emulation(11331): eglMakeCurrent: 0x79f21b5e26e0: ver 2 0 (tinfo 0x79f219aa66c0)
W/IInputConnectionWrapper(11331): getCursorCapsMode on inactive InputConnection
Yet all the package files remained.
Of course I could go into ./ios/ to run pods install to remove pods:
pod install
Analyzing dependencies
Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
Removing Wilddog
Removing WilddogCore
Removing WilddogSync
Downloading dependencies
Using Flutter (1.0.0)
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
[!] Automatically assigning platform `ios` with version `8.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
There is an intuitive way for it.
Install this package
dev_dependencies:
dependency_validator: ^x.x.x
Then run flutter pub run dependency_validator
It will show all the details about the packages installed.
Example: =>
These packages are pinned in pubspec.yaml:
dependency_validator: null -- This is a direct pin.
permission_handler: null -- This is a direct pin.
swipe_to: null -- This is a direct pin.
These packages are used in lib/ but are not dependencies:
connectivity
meta
path
The following packages contain executables, they are assumed to be used:
flutter_native_splash
These packages may be unused, or you may be using assets from these packages:
cupertino_icons
firebase_analytics
http
loading
sign_in_with_apple
delete the hosted folder of .pub-cache in flutter SDK directory
cd path/to/flutter_sdk_directory
rm -rf .pub-cache/hosted
delete the .packages file in the project root directory
cd path/to/project_root_directory
rm -rf .packages
get packages for the project
cd path/to/project_root_directory
flutter pub get
open the project in Android Studio
done.
Sometimes there might be packages that is not used in the project but you have installed sometime during the development stage. To find out those, First go to each dart file and remove the unused imports, then go to pubspec.yaml and comment the packages one by one and save the project. And then refresh the application(NOT HOT RELOAD). if the package us used in the project then it will throw you an error. After repeating the steps on all the packages you will be able to remove all the unwanted packages from your pubspec.
Now, delete the pubspec.lock file, and run the pub get again. Your project will now be having only the required packages and this could be the minimum size achievable.
There's an obvious way which is easy to overlook or think is not feasible.
If using IntelliJ, simply do "Find in files" (SHIFT+CTRL+F on PC, SHIFT+CMD+F on Mac), select "Directory" and choose the lib-folder of your project.
Then go through your list of plugins and search for the name of each one in turn. The plugin isn't used if
there are no search results for its name
it's only used in "generated_plugin_registrant.dart"
the only hits are import statements that are grey (marked as unused by IntelliJ)
Took me less than a minute to eliminate 8 unused plugins using this method.
You can use this three steps to clear this issue
'flutter clean'
Remove the unwanted dependencies in pubspec.yaml
Delete the pubspec.lock
Reload the project and again perform 'pub get' and run the iOS/Android project
This behavior seems to be a bug. You can track it here https://github.com/flutter/flutter/issues/65718
The best way to do this is
flutter clean
If this doesn't work just create a new project copy your old code into the new project and here you can add only the dependencies you want before running pub get.
You can remove by typing in terminal dart pub remove <packagename>
Example : To remove flutter_svg:^0.22.0 ,
type dart pub remove flutter_svg
For more informations, check https://dart.dev/tools/pub/cmd/pub-remove