Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

cocoapods gradle

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`.
like image 224
Aero Wang Avatar asked Aug 20 '18 08:08

Aero Wang


People also ask

Where are all the flutter packages stored?

If you are running Windows as your OS, you can find the packages under the folder that you installed your Flutter SDK to when setting up Android Studio. In my case - using Windows 10 - the path is as follows, where C:\ is my primary harddrive and flutter\ the folder containing the Flutter SDK...

How do I find my package in flutter?

From the terminal: Run flutter pub get . From Android Studio/IntelliJ: Click Packages get in the action ribbon at the top of pubspec. yaml . From VS Code: Click Get Packages located in right side of the action ribbon at the top of pubspec.

Can we delete Pubspec lock file in flutter?

You are welcome, Yes you are right; that's why you may need to keep a backup from your original pubspec. lock before you delete it if it isn't tracked by a source code version control :D I will add it as a note in the answer.


1 Answers

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.

like image 155
Abhay Korat Avatar answered Oct 02 '22 20:10

Abhay Korat