How to Setup Multiple Environments on Android-based Application

Chandan Luthra Jul 23rd, 2019

Before we discuss how to setup multiple environments for an app, it’s important to understand why and when you might need multiple environments. As an app developer, you would like to separate the things like; Base URL, configuration IDs and paid/unpaid functionality for an app that you can achieve the same by multiple environments.

During development, you might face challenges like:

  • How the mobile app work with multiple environments?
  • How to switch between them?

These challenges can be overcome by product variants and Build Types

Android Build Types :-

Once the new project is created, by default it consists of two build types/variants – debug, release.Debug is the build type that is used when we run the application from the IDE directly onto a device.A release is the build type that requires you to sign the APK. The release builds are meant to be uploaded to the play store.Following image shows the default build types.

In the build.gradle by default, only the release build type block is written:
We can add properties on the other build types too. Let’s add new build types and more properties to the buildConfig.
applicationId suffix appends the string to the applicationId of the application.
versionName does the same on the version name present in the defaultConfig.
Now we have 3 build variants:

Android Product Flavors :-

Android Product Flavors are used to create different app versions.App versions can be free or paid.

They can use different environments or APIs. to successfully create the flavors we need to set flavor dimensions. Now syncing the gradle would give you the following product flavors:

Now in our project, the main folder consists of the common logic across all app versions. To write flavor specific code, create a folder with the same name as the flavor.

  • The java classes with the same name in the flavor folders won’t override the main folder.
  • The res folder in the main should only have those directories that are common to all flavors.

Project Structure

Hope this speed up a little on your initial project setup. Cheers!

I hope you appreciate this post and it’s helpful for you.

Chandan Luthra - Director, Product Engineering, Enveu
Chandan Luthra is a co-founder of Enveu, and heads the Engineering department at Enveu. He is an early adopter of OTT tech and has been part of many OTT platforms across the globe. He is developing & building Products and SaaS platforms for more than 13+ years

Add a Comment

Your email address will not be published. Required fields are marked *

Looking for Streaming Solutions?

  • Go-Live on 12+ platforms
  • Zero Revenue Share
  • Multiple Monetization Models
  • 50+ Integrations

get a demo today

Take control of your digital media strategy.
Contact us for a no-obligation demo of the Experience
Cloud, tailor-made for you!

    By Continuing, you agree to our Terms & Conditions and Privacy Policy