0

I just made a Hello World App, but the file size is really big. Is there a way to reduce project file size?

Akif
  • 7,098
  • 7
  • 27
  • 53
  • The file size of *what*? Did you build for Android? iOS? Web? Desktop (which one?). How big *is* you file and what does your app look like? – nvoigt Oct 15 '20 at 06:28
  • Do you mean the size of the project on your computer or the app on your phone? – Jaime Etxebarria Oct 15 '20 at 06:28
  • Does this answer your question? [Flutter apps are too big in size](https://stackoverflow.com/questions/49064969/flutter-apps-are-too-big-in-size) – Hamed Oct 15 '20 at 08:54
  • I mean the project file size , not the apk size – Althaf Budiman Oct 15 '20 at 09:37
  • I too facing same issue. Basic project size is 4mb. If i install cocoapods for iOS, its huge project size. It is very difficult to share source code to others if project size is huge – MaheshPeri19 Mar 24 '21 at 00:10

4 Answers4

7

I think you are talking about project size, not apk or ipa file size. For basic flutter project, size is within 10MB. When we run cocoapods for iOS, all dependencies will download and project size increases to more than 500MB or 1GB also. But this causes for only iOS, not android.

pod deintegrate

did the trick to remove all dependencies whenever you want to distribute source code.

Again you can install all dependencies with below command in ios folder

pod install

Step 1 : flutter clean

Step 2 : in iOS folder of project, pod deintegrate.

Step 3 : For install again, flutter pub get

Step 4 : in iOS folder of project, pod install

Step 5 : flutter build ios (only if you got build errors)

Step 6 : then run app in Xcode or VSCode or Android studio by selecting simulator or real device.

This process will reduce project size and can able to distribute source code via mail.

Dharman
  • 30,962
  • 25
  • 85
  • 135
MaheshPeri19
  • 362
  • 6
  • 12
2

I assume that you are talking about Android Apk. It is preferred to get appbundle, but if you want to get an apk, you should build your apk with --split-per-abi.

flutter build apk --split-per-abi

You can read the official document carefully.

Removing the --split-per-abi flag results in a fat APK that contains your code compiled for all the target ABIs. Such APKs are larger in size than their split counterparts, causing the user to download native binaries that are not applicable to their device’s architecture.

Akif
  • 7,098
  • 7
  • 27
  • 53
  • I think he is talking about project size, not apk or ipa file size. I too facing same issue. Basic project size is 4mb. If i install cocoapods for iOS, its huge project size. It is very difficult to share source code to others if project size is huge. – MaheshPeri19 Mar 24 '21 at 00:09
  • Already tried twice, not solved my issue and app size. Any other suggestion? – Kamlesh Jul 30 '21 at 11:44
1

I think so you took apk file from Your_project\build\app\outputs\apk\debug\app-debug.apk If so definitely your apk size will be larger.

STEP 1 : In your project terminal, type flutter build apk and then press Enter.

STEP 2 : And then after completion of process. Get into Your_project\build\app\outputs\flutter-apk\app-release.apk Choose the app-release.apk, this file size will be smaller now.

Abilash S
  • 235
  • 3
  • 9
0

Try this command. I was also searching for the answer of this and later found this command.

flutter build apk --release --tree-shake-icons --split-per-abi

for explanation, refer this link https://suryadevsingh24032000.medium.com/size-matters-reducing-flutter-app-size-best-practices-ca992207782

Sumit Kumar
  • 678
  • 4
  • 19