使用flavor variant发布付费应用

时间:2017-11-30 08:08:20

标签: android

我想发布付费应用和免费应用 我使用此代码创建了免费和付费的味道

 productFlavors {
    free {
        applicationId "com.example.myapp.free"
        versionName "1.0-free"
        // this boolean can be accessed in java classes by using BuildConfig class
        // and now you can identify if your app is the paid version or not
        buildConfigField "boolean", "PAID_VERSION", "false"
    }

    paid {
        applicationId "com.example.myapp.paid"
        versionName "1.0-paid"
        buildConfigField "boolean", "PAID_VERSION", "true"
    }
}

我想知道如何上传此应用 我们需要两个diffretnt apk for the paid(pay relese apk和免费apk) 或单个apk

我需要在playstore中提供两种变体

2 个答案:

答案 0 :(得分:0)

你有这种类型的Build变体,如图所示:在你的情况下,你可以看到paidDebug和freeDebug选项。

如果你想发布付费版本,那么你必须选择paidDebug,如果你想发布免费版本,那么你必须选择freeDebug。

enter image description here

答案 1 :(得分:0)

如果您有两种风味变体

喜欢

  1. 免费包名为

    applicationId“com.example.myapp.free”

  2. 支付包名称为

    applicationId“com.example.myapp.paid”

  3. 两者都是不同的applicationId,所以你需要在Play商店中的两个不同的应用程序上传,因为你的applicationId是一个Playstore app id所以它必须是唯一的

    您必须在两种风格中删除此行并使用常见的applicationId

    然后

    按以下方式处理

     defaultConfig {
            applicationId "com.example.myapp"
    }    
    productFlavors {
        free {
            versionName "1.0-free"
            buildConfigField "boolean", "PAID_VERSION", "false"
            buildConfigField "String", "BuildType", "Free"
        }
    
        paid {
            versionName "1.0-paid"
            buildConfigField "boolean", "PAID_VERSION", "true"
            buildConfigField "String", "BuildType", "Paid"
        }
    }
    

    处理java代码

    public void manageFeaturesWithBuildType()
        {
            String buildType = BuildConfig.BuildType;
            if(buildType.equals("Paid"))
            {
                //Here Enable or Disable your features for paid Build
            }
            else
            {
                //Here Enable or Disable your features for free Build
            }
        }