DEV Community

Pere Sola
Pere Sola

Posted on • Updated on

12 things I have learnt while building a Flutter app for development and production

    1. I went a bit wild changing things in AndroidManifest.xml, among which the package= property. Well don't, or at least make sure you also change it in the MainActivity.kt file. Otherwise it will crash upon loading, like it happened to me. Kudos to this answer in SO for putting me on the right direction.
    1. If you make API calls in your app, you need to specify permissions for internet, read more about it here. This Flutter cookbook can also be helpful.
    1. Multidex support. You can read about it here. The docs say that The simplest way is to opt into multidex support when prompted.. I was wondering: prompted when? From what I have seen when trying to run the app on an android device for development, you get indeed prompted, so just say y:

Image description

  • 4. When running your local env in an Android phone, you have access to the Flutter dev tools. You should get the link in the terminal after running flutter run:

Image description

Image description

-5. flutter run --verbose will provide logs of what went wrong. It is helpful.

-6. flutter logs will show logs from the devices you are connected to.

-7. You can pass env variables at build time with --dart-define (see here), like so:

flutter run --dart-define VARIABLE_ONE=test --dart-define VARIABLE_TWO=42

or

flutter build appbundle --dart-define VARIABLE_ONE=test --dart-define VARIABLE_TWO=42

(Source)

They can be "fished" in the code like so, with a fall back value too. Also explained a bit here.

BUT, BIG WARNING: do NOT miss const before String.fromEnvironment(), otherwise it will silently fail, see https://github.com/flutter/flutter/issues/55870.

Other related and useful articles:

-8. When building for production, you may want to obfuscate your code to make it harder for malicious actors to find stuff in your code they should not be finding:

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

One of the questions I had is.. what is good location for these symbol map files? This SO thread gave answers, seems like somewhere in build/ directory is a good place, like build/app/outputs/symbols.

-9. Even if you increase the version number of the app, you also need to increase the build number. Otherwise, you will get the Version code 1 has already been used. Try another version code error in the Play store. More info here.

-10. You can "inspect" an .apk or .aab (for app bundle) file in Android Studio to know what value was passed into Android Manifest file (if you are passing a value, ofc). You will need to build from Android Studio (via terminal so u can pass the --dart-define variables. You then import the file, and you can find the manifets file in the /manifest folder:

Image description

Image description

-11. If you need to troubleshoot what env variables were passed during build, add .zip to bundle file (.apk or .aab). This will make it unzippable. You do so in, for instance, a folder called unzipped_stuff, and look for the file libapp.so in \build\app\outputs\bundle\unzipped_stuff\base\lib\arm64-v8a. Open it in a text editor (I am on windows) and search for the value you passed. If it's there, it worked. If you don't find it, something went wrong. Source here. Related articles:

-12. If you started versioning your builds, like 1.2.0+6 you need to increment at every build, otherwise Google Play will complain. I learnt this in this Stackoverflow thread.

Top comments (0)