FlutterWorld
Published in

FlutterWorld

Flutter Obfuscation And Build Optimization

Once we are done with the development of the app somethings are really important like code security, app size, and obfuscation. This blog will explain how you can obfuscate the application in flutter? and how the app size can be reduced in simple steps.

In software development, obfuscation is the deliberate act of creating source or machine code that is difficult for humans to understand. This is done to deter reverse engineering which provides code in place and getting leak anywhere.

There are two ways to create a build and upload it to store

  1. App Bundle
  2. Apk

You need to run the below commands as per your need, everyone has their own purpose.

For AppBundle:

Without splitting:

flutter build appbundle --obfuscate --split-debug-info=/<directory>

Splitting:

flutter build appbundle --target-platform android-arm,android-arm64,android-x64 --obfuscate --split-debug-info=/<directory>

For APK:

Without splitting:

flutter build apk --obfuscate --split-debug-info=/<directory>

Splitting:

flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi --obfuscate --split-debug-info=/<directory>

The /<directory> can be replaced with the relative path of the project or exact location.

Ex:

  1. ./ProjectFolderName/debug(It will create ProjectFolderName folder inside your project directory)
  2. /Users/apple/Desktop/items/debug (It will be specific path of folder )

Note: Works only for Flutter version v1.16.2 or higher.

By default, fat apk contains arm v7, arm v8 and x64 which increases apk size, which you don’t want to. So, when you split it, you have separate binaries that you can upload to the store and thus reducing the size of the apk that a user would need to download.

Few questions which you might have after reading the above things are explained via the below questions which are taken from flutter docs

When should I build app bundles versus APKs?

The Google Play Store recommends that you deploy app bundles over APKs because they allow more efficient delivery of the application to your users. However, if you’re distributing your application by means other than the Play Store, an APK may be your only option.

What is fat APK?

A fat APK is a single APK that contains binaries for multiple ABIs embedded within it. This has the benefit that the single APK runs on multiple architectures and thus has wider compatibility, but it has the drawback that its file size is much larger, causing users to download and store more bytes when installing your application. When building APKs instead of app bundles, it is strongly recommended to build split APKs, as described in build an APK using the --split-per-abi flag.

What are the supported target architectures?

When building your application in release mode, Flutter apps can be compiled for armeabi-v7a (ARM 32-bit), arm64-v8a (ARM 64-bit), and x86–64 (x86 64-bit). Flutter does not currently support building for x86 Android (See Issue 9253).

Reducing app size

Developers are concerned with the size of their compiled app. As the APK, app bundle, or IPA version of a Flutter app is self-contained and holds all the code and assets needed to run the app, its size can be a concern. The larger an app, the more space it requires on a device, the longer it takes to download, and it may break the limit of useful features like Android instant apps.

When building a release version of your app, consider using the --split-debug-info tag. This tag can dramatically reduce code size.

Some of the other things you can do to make your app smaller are:

  • Remove unused resources
  • Minimize resource imported from libraries
  • Compress PNG and JPEG files

--

--

--

The fastest growing community which makes development easier

Recommended from Medium

How To Install Apache Airflow

Technical Debt: Experiences, Learnings, and Vision @NonStop

SQL Database

Advanced Configuration for ShinyProxy

Novel Generator

Everything is an object!

Extract and store data from images

DIGITAL ANALYTICS | CXL MINIDEGREE | REVIEW FOR WEEK 3

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jitesh Mohite

Jitesh Mohite

I am technology enthusiastic, want to learn things quickly and dive deep inside it. I always believe in developing logical things which makes impact on end user

More from Medium

Getting Ready Flutter App For Google Play

Building a Clubhouse clone using 100ms in Flutter

Working with APIs in flutter using Dio Package

How to Integrate Web-Sockets with your Server in Flutter