Creating demo and full version app based on one code base/project

前端 未结 3 778
别那么骄傲
别那么骄傲 2021-01-03 03:53

I have developed one Android app in one project with Eclipse - it\'s structured (coming from iPhone) so one constant defines whether it\'s the demo or the full version.

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-03 04:28

    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

提交回复
热议问题