Friday, July 1, 2022

Flutter – Set Target File Based on Android Product Flavors

Flutter is a popular cross-platform to develop applications for different platforms. Developers wish to use them for attractive attributes. If you are a developer, you have a good opportunity to distribute the app on different platforms for production and development environments. 

If you are looking for a complete Android and iOS application solution, go with Flutter Agency. As a leading Flutter development agency, they have vast experience in cross-platform application development, making it easy for an enterprise to manage their business through mobile devices. Professionals provide you with a simple guideline to build the ideal flavor for an app. Professionals provide you with a simple guideline to build the ideal flavor for an app. 

When it comes to the development stage, you may share an application with internal testers with the backend configured for development

You use the dev variant for the app and share them with internal testers. However, if you roll out an app and keep the production backend ready, you want a variant of the same thing that links to the production backend and calls them prod flavor.

Set up flutter app:

Developers create apps with popular flavors like dev and prod. When building flavor, you need to follow some instructions carefully.

Configure app and connect to firebase:

You can create an app for android in the firebase console. It is necessary to download google service-info.plist and google-services.json. Developers bring you detailed instructions to add firebase to the project. Creating an ideal class allows developers to summarize the app environment, flavor type, and specific name of flavor. 

class AppConfig {final String appName;final String flavor;AppConfig({@required this.appName, @required this.flavor});}

Dev flavor entry point:

Build file lib/main._dev.dart is necessary to run the application in dev flavor. Depending on the flavor, you may assign a flavor type and specification name for the app. 

void main() async {AppConfig devAppConfig = AppConfig(appName: ‘CounterApp Dev’, flavor: ‘dev’);Widget app = await initializeApp(devAppConfig);runApp(app);}

Prod flavor entry point:

Build file lib/main_prod.dart is vital to run the application in prod flavor. You can allot a specific name and flavor type by considering flavor. 

void main() async {AppConfig devAppConfig =AppConfig(appName: ‘CounterApp Prod’, flavor: ‘prod’);Widget app = await initializeApp(devAppConfig);runApp(app);}

Firebase configuration:

The essential thing is to download google-services.json files for the firebase product. You can save it in a temporary location on the device. You need to create different folders like android/app/src.dev and android/app/src/prod for a different flavor. 

Firebase configuration files can be placed under flavor folders under the android/app/src/ folder. You can copy the respective google-services.json files into the ideal flavor folder.

For dev flavor – you must build android/app/src/dev/google-services.json

For prod flavor – you must build android/app/src/prod/google-services.json

Setup flavor for android: 

Once you decide to set up a flavor for android, you configure environment variants on the platform. At that moment, you can focus on the firebase project setup for the dev and prod environment or flavor. 

Developers start with a basic app and connect them to the same firebase database. It is vital to build and test the app locally. 

Creating good flavor for the dev and prod environment is necessary. You can build an android app in the project, download separate files, and manage them very handy. 

android {defaultConfig {applicationId “com.pcc.counterapp”minSdkVersion 16targetSdkVersion 30versionCode flutterVersionCode.toInteger()versionName flutterVersionName}…flavorDimensions “counterapp”productFlavors {dev {dimension “counterapp”applicationIdSuffix “.dev”resValue “string”, “app_name”, “Counter App Dev”versionNameSuffix “.dev”}prod {dimension “counterapp”applicationIdSuffix “.prod”resValue “string”, “app_name”, “Counter App Prod”versionNameSuffix “.prod”}}}

Dev flavor utilizes default applicationId as com.kanily.flavortest. 

Prod flavor needs flavor specific applicationId as describe in prod flavor definition com.kanily.flavortest.prod.

Developers define a string resource known as app-name that uses androidmaniest.xml rather than hard coding.

Google-services.json can be placed under the source folder that matches with flavor. 

Aware of important points:

With the advent of technology, the internet is the best source to gather useful information about flavors for the flutter app. You need to be aware of important things to deal with flavor in android. You may also speak with an expert well-known in flutter flavoring.

  • All flavors can install concurrently on a device with a different app id. 
  • Users, testers, and developers use different application names for different flavors and differentiate them from each other.
  • Each flavor pointing comes with its own Firebase project.
  • It is better to take care of keeping files in the required folder name that same as flavor.
  • You can use commands like flutter run –flavor dev or flutter run –flavor prod.
  • The app can install easily on a device and run them in parallel. 

Include different icons for different flavors:

If a different name is not enough, you may create a different app icon that suits for clear visual distinction. You can install different flavors on the device. Developers focus on the default launcher icon from flutter and build an icon for dev and prod.

Based on the flavor you choose, you can look at the default. You can locate the android/app/src/main/res folder and restore an existing file of all sizes. Developers add the dev icon to a default folder. 

For prod flavor, creating a res folder is ideal for the prod folder and inserting all specific folders. After that, you will go to the directory structure and check files. Use the separate icon in the respective folder. 

  • Android platform focuses on flavor specific directory first.
  • If it does not find anything in the directory, it will return to the default directory known as main.
  • Flavors are an important thing to create an app for environments like dev and prod.
  • Development version app determines API host at dev.api.myapp.com
  • Production version app determines api.myapp.com

It is the best option for builders to prevent hard-coding values to variables and create an app for the environment manually. Developers approach flavor to bring value. So, you can use flavor properly to set up a target for the production and dev environment. 

Conclusion:

Business owners gain proper support and service from flutter app developer and pick up the fully functional app. Experts follow proper instructions to create an app icon for different flavors in the android platform.