Create Free/Paid versions of Application from same code

后端 未结 7 1384
Happy的楠姐
Happy的楠姐 2020-11-30 18:36

So I\'m coming down to release-time for my application. We plan on releasing two versions, a free ad-based play-to-unlock version, and a paid fully unlocked version. I have

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 19:11

    It's very simple by using build.gradle in Android Studio. Read about productFlavors. It is a very usefull feature. Just simply add following lines in build.gradle:

    productFlavors {
        lite {
            packageName = 'com.project.test.app'
            versionCode 1
            versionName '1.0.0'
        }
        pro {
            packageName = 'com.project.testpro.app'
            versionCode 1
            versionName '1.0.0'
        }
    }
    

    In this example I add two product flavors: first for lite version and second for full version. Each version has his own versionCode and versionName (for Google Play publication).

    In code just check BuildConfig.FLAVOR:

    if (BuildConfig.FLAVOR == "lite") {
       // add some ads or restrict functionallity
    
    }
    

    For running and testing on device use "Build Variants" tab in Android Studio to switch between versions: enter image description here

提交回复
热议问题