Search code examples
javaandroidandroid-productflavorsandroid-build-type

Build Lite and Full Version of app


I'm creating an app that will have a Lite and a Full version of it, one being free and the other having a small fee. Since I don't want to have to distinct projects to avoid updating errors (like updating a module in one version only) I set up a boolean in my Application class.

I was wondering how can I determine the value of that boolean with information from the app. I know I can create app with different Flavors and Build Types but I'm kind of lost in all that. Can you help?

Thanks!


Solution

  • I assume you're using Gradle and AndroidStudio, right? You can create BuildConfig values for each flavor and/or buildType:

    1. Goto your app/build.gradle file

    2. If you prefer to put your variable at

    a. buildType:

    buildTypes {
        debug {
            versionNameSuffix "-beta"
            buildConfigField "Boolean", "PAYED", "false"
        }
    }
    

    b. flavor

    productFlavors {
        premium {
            buildConfigField "Boolean", "PAYED", "true"
        }
    }
    

    And than, after a sync & build you can access those variables in your code depending on build/flavor you've chosen:

    if (BuildConfig.PAYED) {
        // Do your stuff
        ...
    }