Flutter Xcode build failed due to missing dependencies even when those have been deleted from pubspec.yalm - flutter

When I add a dependency to the pubspec.yaml file no matter if the IDE runs the pub get command or if I run it manually, it seems like the packages are being imported correctly (or that is what I think), however, if I "change my mind" and delete the package from the pubspec.yaml file, and again pub get, I am unable to build the app anymore, seems like the packages are still linked somehow to the app, even when there is no code related to them, the only way I can get back to work is by cleaning up all... e.g.
cd ios
cd ..
pod deintegrate
flutter clean
flutter pub cache repair
flutter pub get
cd ios
Pod install
Pod repo update
Maybe I am missing a step when working with dependencies.

Related

Manually deleted package in External Libraries/Dart Packages not reappearring (Android Studio)

I manually deleted a package in External libraries/dart packages. Now I tried to run packages get again. The package(tesseract_ocr) did not appear in External libraries/dart packages.
I tried removing it in pubspec.yaml and re-adding it but did not appear again. I tried deleting .pub-cache and run packages get again. I tried flutter clean, flutter pub cache repair, flutter pub cache add tessarect_ocr and packages get so many times but none of them made tessarect_ocr package reappear in External libraries/dart packages. Please Help. Thanks in advance!
Try
dart pub cache clean
or
flutter pub cache clean
facing the same issue I did the following things:
1.
flutter pub cache clean
which reinstalled all the packages
2. `
flutter pub get
`
which update the dependencies and it works.

Flutter - Overridden dependencies

After running "flutter pub get", I got this error:
Warning: You are using these overridden dependencies:
! path 1.6.4
That's not an issue. That happens because you (or any other transitive dependency) may be overriding some dependency that you are already using. For example, if you are using path: 0.X.X and some other dependency use dependency_overrides to make sure that is using path: 1.6.4, it will present you that message.
Overall, you shouldn't have to worry with that and sometimes it is actually required in order to some dependencies work all together.
Please give more details so that i can answer it better. Attach your pubspec.yaml.
But now i can tell you some methods which should work..
first of all see if you are using the latest version of all dependencies or not then:
try:
restarting your ide
flutter clean
if these two don't work then at last try
flutter pub cache repair
I encountered the same error after cloning a flutter repository. I initially mistook the error for being a build issue when it's just a warning that won't stop your app from running.
I solved the build issue I was having with the freshly cloned project by running this command inside the app's root directory: flutter pub run build_runner build

Should .packages files be auto-generated for pub packages cached from git?

The reason I'm asking it that I'm working on a package, actually flutter plugin and when I reference it local in my apps pubspec.yaml using path: everything works fine and I can see a .packages file being generated inside the local plugin workdir. Now if I now try to reference the plugin using git: in my apps pubspec, flutter pub get is happy BUT when I try to run the app, the build fails with an error mesg:
Launching lib/main.dart on XYZ in debug mode...
/home/maksimlin/.pub-cache/git/edit_exif-3c87efc135c1269b5961ff73696a19e988132ad7/.packages does not exist.
Did you run "flutter pub get" in this directory?
FAILURE: Build failed with an exception.
* Where:
Script '/home/maksimlin/fvm/versions/dev/packages/flutter_tools/gradle/flutter.gradle' line: 896
* What went wrong:
Execution failed for task ':edit_exif:compileFlutterBuildDebug'.
> Process 'command '/home/maksimlin/fvm/versions/dev/bin/flutter'' finished with non-zero exit value 1
and sure enough if I copy the .packages autogenerated file from my local plugin workdir into the the pub-cache location my app builds fine
So is something broken with pub auto-generating .packages for cached from git packages? or have I done something wrong with my plugin?
Unfortunately I can't seem to find much (any) documentation on the usage of .package files, especially for cached packages.
# Generated by pub on 2020-10-01 15:23:17.745081.
args:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/args-1.6.0/lib/
bloc:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/bloc-4.0.0/lib/
characters:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0-nullsafety.2/lib/
charcode:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.1.3/lib/
charts_common:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/charts_common-0.9.0/lib/
cloud_firestore:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.0/lib/
cloud_firestore_platform_interface:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_platform_interface-2.0.0/lib/
cloud_firestore_web:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore_web-0.2.0/lib/
collection:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0-nullsafety.2/lib/
convert:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/convert-2.1.1/lib/
crypto:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-2.1.5/lib/
custom_switch:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/custom_switch-0.0.1/lib/
dio:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/dio-3.0.10/lib/
easy_localization:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/easy_localization-2.3.3/lib/
file:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/file-5.2.1/lib/
firebase:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/
firebase_auth:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-0.18.0/lib/
firebase_auth_platform_interface:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-2.0.0/lib/
firebase_auth_web:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_web-0.3.0/lib/
firebase_core:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core-0.5.0/lib/
firebase_core_platform_interface:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_platform_interface-2.0.0/lib/
firebase_core_web:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_web-0.2.0/lib/
flutter:file:///C:/Src/flutter/packages/flutter/lib/
flutter_bloc:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_bloc-4.0.1/lib/
flutter_localizations:file:///C:/Src/flutter/packages/flutter_localizations/lib/
flutter_web_plugins:file:///C:/Src/flutter/packages/flutter_web_plugins/lib/
google_fonts:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/google_fonts-1.1.0/lib/
http:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/
http_parser:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.4/lib/
intl:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/intl-0.16.1/lib/
js:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.2/lib/
logging:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/logging-0.11.4/lib/
matcher:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.9/lib/
material_design_icons_flutter:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/material_design_icons_flutter-4.0.5245/lib/
meta:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0-nullsafety.2/lib/
nested:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/nested-0.0.4/lib/
path:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/
path_provider:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.11/lib/
path_provider_linux:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/lib/
path_provider_macos:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+3/lib/
path_provider_platform_interface:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_platform_interface-1.0.2/lib/
pedantic:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.9.2/lib/
platform:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/platform-2.2.1/lib/
plugin_platform_interface:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/plugin_platform_interface-1.0.2/lib/
process:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/process-3.0.13/lib/
provider:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/provider-4.3.2/lib/
quiver:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.3/lib/
shared_preferences:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.8/lib/
shared_preferences_linux:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+1/lib/
shared_preferences_macos:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+10/lib/
shared_preferences_platform_interface:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_platform_interface-1.0.4/lib/
shared_preferences_web:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/lib/
sky_engine:file:///C:/Src/flutter/bin/cache/pkg/sky_engine/lib/
source_span:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.7.0/lib/
stack_trace:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.5/lib/
string_scanner:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.5/lib/
term_glyph:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib/
typed_data:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.3.0-nullsafety.2/lib/
vector_math:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0-nullsafety.2/lib/
xdg_directories:file:///C:/Src/flutter/.pub-cache/hosted/pub.dartlang.org/xdg_directories-0.1.0/lib/
website:lib/
This is my .package file here you can see that there is every package that I have used to along with directory(file:///C:/Src/flutter is my directory).
.package is an autogenerated file so you can delete the older one and run flutter pub get so it will generate a newer one.

Flutter: Can I force flutter to install packages from pubspec.lock?

Does anyone know if you can do reproducible builds in Flutter? There doesn't seem to be an option to install from the pubspec.lock file. I would of expected something like:
flutter pub get --from-lockfile
The problem is that the pubspec.lock is modified on every run of flutter pub get so I can't easily go back to the previous state of the dependencies at different points in the git history.
I would of expected it to behave like the yarn.lock or package-lock.json which allow you to create reproducible builds of the project.
As mentioned in the doc, pub get should fetch what's in pubspec.lock if the lockfile contains the solution for the dependency requirements and constraints configured in pubspec.yaml. Simply put, if pubspec.yaml and pubspec.lock isn't modified, and neither Dart nor Flutter SDK is upgraded, then pub get should fetch what's listed in pubspec.lock.
If you're still having issues and can be reproducible, you can file an issue here https://github.com/dart-lang/pub/issues - as jonasfj also mentioned in the Comments.

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