Best practice for creating mobile(ios, android) app artifact for non-prod and prod environments

Viewed 116

I need to create a mobile app artifact for multiple env. The goal is to promote the same artifact across multiple envs (dev, qa, preprod and prod). The mobile artifact uses a saas url which changes from env to env. Please let me know the best practice to do so.

Currently when the artifact passes qa I create another artifact for pre-prod and finally for prod which is time-consuming and prone to mistakes.

I am thinking of creating an active env url and release version api. What is the best practice?

Thanks,

2 Answers

I think android-flavors will solve your problem.

I look like these examples below.

  flavorDimensions "default"
    productFlavors{
        dev{
            applicationId "com.amitgupta.trust_app_android.dev"
        }
        staging{
            applicationId "com.amitgupta.trust_app_android.staging"
        }
        qa{
            applicationId "com.amitgupta.trust_app_android.qa"
        }
        production{
            applicationId "com.amitgupta.trust_app_android.production"
        }

    }

You make also use different URLs based on Different environment.

flavorDimensions "version"
    productFlavors {
        QA {
            buildConfigField "String", "BASE_URL", '"http://qa.com/api/"'
        }
        production {
            buildConfigField "String", "BASE_URL", '"http://production.com/api/"'
        }
    }

Please, look at these for its implementation.

https://medium.com/@hsmnzaydn/configuration-product-flavors-and-build-variants-in-android-bb9e54d459af

https://www.journaldev.com/21533/android-build-types-product-flavors

For iOS: You can make use of Schemes and Build configurations in Xcode. Here's the official documentation: https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/BasingBuildConfigurationsonConfigurationFiles.html

I hope this will be of any help.

The following is true if you use gradle:

  1. For top level build.gradle, define appId parameter:
allprojects {
    ext {
        appId = 'com.my.app'
    }
}
  1. For app module's build.gradle, define flavors and use the above parameter:
android {
    def globalConfig = rootProject.extensions.getByName("ext")

    productFlavors {
        dev {
            applicationId globalConfiguration["appId"] + ".dev"
            ...
            buildConfigField "String", "YOUR_ENDPOINT", "\"https://my.dev.env/\""
        }
        qa {
            applicationId globalConfiguration["appId"] + ".qa"
            ...
            buildConfigField "String", "YOUR_ENDPOINT", "\"https://my.qa.env/\""
        }
}
  1. Build app using specific flavor + use BuildConfig.YOUR_ENDPOINT in code.
Related