For those who’ve ever tried to publish a Flutter bundle, you’re doubtless acutely aware of the scale of your bundle. As an example, pub.dev doesn’t allow Flutter packages to be bigger than 100 MB. This can be a helpful rule to make sure that packages (and subsequently the tasks that use these packages) don’t develop into too overwhelmed or bloated.
So if you end up staring down this ominous pub.dev error message after making an attempt to publish, don’t panic.
There are a selection of reasons why this might need popped up that aren’t associated to your bundle truly being too massive. What I imply by that’s that the core of your bundle (what the developer might want to use) is probably going not SO massive as to be forbidden entry to pub.dev.
What IS extra doubtless is that it’s essential to run some fast instructions to assist scale back and re-determine the file and knowledge allocation of your challenge. There are a number of great ways to scale back the scale of your Flutter app or bundle on the market. From decreasing asset sizes, splitting up a fats APK, and utilizing packages to optimize your app, there’s a number of choices to discover.
For this weblog publish, I needed consolidate and canopy what I discovered to be the quickest and easiest methods to trim down my packages earlier than publishing. Let’s soar proper in.
The very first thing to do is replace your
.pubignore file. Put something you don’t need or want
pub.dev to find out about right here. By placing these recordsdata right here they received’t be thought of within the bundle publishing course of.
THIS! This was extremely useful for me. The command
flutter clear works by deleting varied directories in your Flutter app that aren’t wanted for publishing. In line with this post on Flutter Company, “After executing the flutter clear command we’d see that it’s going to delete the dart-tools folder, android folder, and iOS folder in our utility with debug file.”
For those who’re publishing a bundle to pub.dev, it will be significant that you’ve got an
instance listing within the root of your challenge. This manner it’ll present up beneath the instance tab on pub.dev.
Whilst you may have greater than only one instance dart to file to run your bundle regionally (like say in case you cd into instance to run your app), in an effort to publish it you simply want your
lib/important.dart file and even simply an
instance.dart file within the root of the instance listing.
Because you don’t want that a lot on this listing to publish to pub.dev, you possibly can run
flutter clear in your instance listing. Within the command line, whereas within the root of your bundle, merely
cd instance/ after which execute
flutter clear. You can even embody varied components of your
instance listing in your
You can even take away the challenge measurement by eradicating unneeded cached data from the git historical past. To do that you possibly can merely kind the beneath in your command line.
git rm -r--cached
That is extra helpful for staging recordsdata for removing within the repo however it may possibly assist declutter your distant and scale back your repo measurement. You can even strive
git filter-repo and
git filter-branch (although
filter-repo is most well-liked). You may learn extra about these instructions here.