Requirements of Native Programming While Flutter project is on the release

Why do we need a native power when launching the flutter project to the market? Let’s learn together :)

Kaan Enes KAPICI
Flutter Students Club
6 min readJan 17, 2022

--

Yes, As you know, there are popular languages and frameworks in the software world in today’s technology. One of the languages that have been increasing in popularity lately is Flutter, which is the apple of everyone’s eye. Everyone from 7 to 70, from individual to corporate companies develops projects with Flutter. Everything is going well, projects are written, tests are done, approvals are received, but when it comes to putting the project on the market, things get a little complicated. This is where the expected power (aka native) comes to our rescue. So how does the process work here? Let’s see together..

Build and release an Android app

During a typical development cycle, you test an app using flutter run at the command line, or by using the Run and Debug options in your IDE.

Before publishing, you might want to change or put some touches on your app.

1) Adding a launcher icon

When a new Flutter app is created, it has a default launcher icon. To customize this icon, you might want to check out the flutter_launcher_icons package. This is actually a known way, but it may be necessary to handle this part on the native side. But How?

  1. In the [project]/android/app/src/main/res/ directory, place your icon files in folders named using configuration qualifiers. The default mipmap- folders demonstrate the correct naming convention.
  2. In AndroidManifest.xml, update the application tag’s android:icon attribute to reference icons from the previous step (for example, <application android:icon="@mipmap/ic_launcher" ...).
  3. To verify that the icon has been replaced, run your app and inspect the app icon in the Launcher.

2) Enabling Material Components

Imaged By Uxpin

If your app uses Platform Views, you may want to enable Material Components by following the steps described in the Getting Started guide for Android.

For example:

  1. Add the dependency on Android’s Material in

<my-app>/android/app/build.gradle:

To find out the latest version, visit Google Maven.

2. Set the light theme in <myapp>/android/app/src/main/res/values/styles.xml:

3. Set the dark theme in

<my-app>/android/app/src/main/res/values-night/styles.xml

3) Signing the app

To publish on the Play Store, you need to give your app a digital signature. Use the following instructions to sign your app.

On Android, there are two signing keys: deployment and upload. The end-users download the .apk signed with the ‘deployment key’. An ‘upload key’ is used to authenticate the .aab / .apk uploaded by developers onto the Play Store and is re-signed with the deployment key once in the Play Store.

4) Create an upload keystore

If you have an existing keystore, skip to the next step. If not, create one by either:

On Mac/Linux or Windows, use the following command:

I put it on the bottom line because it doesn’t fit the whole screen :)

This command stores the upload-keystore.jks file in your home directory. If you want to store it elsewhere, change the argument you pass to the -keystore parameter. However, keep the keystore file private; don’t check it into public source control!

5) Configure signing in gradle

Configure gradle to use your upload key when building your app in release mode by editing the [project]/android/app/build.gradle file.

  1. Add the keystore information from your properties file before the android block:

Load the key.properties file into the keystoreProperties object.

2. Find the buildTypes block:

3. And replace it with the following signing configuration info:

6) Reviewing the app manifest

Review the default App Manifest file, AndroidManifest.xml, located in [project]/android/app/src/main and verify that the values are correct, especially the following:

applicationEdit the android:label in the application tag to reflect the final name of the app.uses-permissionAdd the android.permission.INTERNET permission if your application code needs Internet access. The standard template does not include this tag but allows Internet access during development to enable communication between Flutter tools and a running app.

7) Reviewing the build configuration

Review the default Gradle build file, build.gradle, located in [project]/android/app and verify the values are correct, especially the following values in the defaultConfig block:

applicationIdSpecify the final, unique (Application Id)appidversionCode & versionNameSpecify the internal app version number, and the version number display string. You can do this by setting the version property in the pubspec.yaml file. Consult the version information guidance in the versions documentation.minSdkVersion, compilesdkVersion, & targetSdkVersionSpecify the minimum API level, the API level on which the app was compiled, and the maximum API level on which the app is designed to run. Consult the API level section in the versions documentation for details.buildToolsVersionSpecify the version of Android SDK Build Tools that your app uses. Alternatively, you can use the Android Gradle Plugin in Android Studio, which will automatically import the minimum required Build Tools for your app without the need for this property.

8) Build an app bundle

This section describes how to build a release app bundle. If you completed the signing steps, the app bundle will be signed. At this point, you might consider obfuscating your Dart code to make it more difficult to reverse engineer. Obfuscating your code involves adding a couple flags to your build command, and maintaining additional files to de-obfuscate stack traces.

From the command line:

  1. Enter cd [project]
  2. Run flutter build appbundle
    (Running flutter build defaults to a release build.)

The release bundle for your app is created at [project]/build/app/outputs/bundle/release/app.aab.

By default, the app bundle contains your Dart code and the Flutter runtime compiled for armeabi-v7a (ARM 32-bit), arm64-v8a (ARM 64-bit), and x86–64 (x86 64-bit).

8.a) Test the app bundle

An app bundle can be tested in multiple ways — this section describes two.

8.a.1) Offline using the bundle tool

  1. If you haven’t done so already, download bundletool from the GitHub repository.
  2. Generate a set of APKs from your app bundle.
  3. Deploy the APKs to connected devices.

8.a.2) Online using Google Play

  1. Upload your bundle to Google Play to test it. You can use the internal test track, or the alpha or beta channels to test the bundle before releasing it in production.
  2. Follow these steps to upload your bundle to the Play Store.

9) Build an APK

Imaged By Webtekno

Although app bundles are preferred over APKs, there are stores that don’t yet support app bundles. In this case, build a release APK for each target ABI (Application Binary Interface).

If you completed the signing steps, the APK will be signed. At this point, you might consider obfuscating your Dart code to make it more difficult to reverse engineer. Obfuscating your code involves adding a couple flags to your build command.

From the command line:

  1. Enter cd [project]
  2. Run flutter build apk --split-per-abi
    (The flutter build command defaults to --release.)

This command results in three APK files:

  • [project]/build/app/outputs/apk/release/app-armeabi-v7a-release.apk
  • [project]/build/app/outputs/apk/release/app-arm64-v8a-release.apk
  • [project]/build/app/outputs/apk/release/app-x86_64-release.apk

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.

10) Install an APK on a device

Follow these steps to install the APK on a connected Android device.

From the command line:

  1. Connect your Android device to your computer with a USB cable.
  2. Enter cd [project].
  3. Run flutter install.

Publishing to the Google Play Store

For detailed instructions on publishing your app to the Google Play Store, see the Google Play launch documentation.

Imaged By Mobikul

As a result, we need to know some native processes while sending our project to the play store in flutter. Build and gradle processes are almost the same as android processes, but we also need to know which build and where to use it.

If you want to ask any question about me or tutorial you will find me on Twitter or LinkedIn.

Thanks for reading. Have a good coding!!

--

--

Kaan Enes KAPICI
Flutter Students Club

Hi everybody, I’m Kaan. Senior Application(Android) Engineer at @TurkTelekom/Innova - Ex @QnbFinansbank Love cats and dogs.🐶🐈. Writing whatever I want..