在Android项目中添加新口味

时间:2019-01-14 13:29:01

标签: android android-gradle android-flavors android-flavordimension

我从未在gradle文件中使用productFlavors。我在github中搜索并找到了一些示例

https://github.com/ptyagicodecamp/android-recipes/tree/develop/Flavors

这是一个项目结构

enter image description here

我想自己添加新的风味。我试图添加

enter image description here

这是gradle文件代码

android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
    applicationId "org.pcc.flavors"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

flavorDimensions "version"

productFlavors {
    freeVersion {
        //select the dimension of flavor
        dimension "version"
        //configure applicationId for app published to Play store
        applicationId "com.pcc.flavors.free"
        //Configure this flavor specific app name published in Play Store
        resValue "string", "flavored_app_name", "Free Great App"
    }
    paidVersion {
        dimension "version"
        applicationId "com.pcc.flavors.paid"
        resValue "string", "flavored_app_name", "Paid Great App"
    }
    betaflovers {
        dimension "version"
        applicationId "com.pcc.flavors.betaflovers"
        resValue "string", "flavored_app_name", "Paid Great App"
    }
  }
 }

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso- 
 core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

您可以看到我试图在我的项目中添加betaflovers,但是它没有正确添加,因为betaflovers和freeVersion风格并不相同。 如何添加新版本,例如freeVersion和paidVersions? 谢谢

0 个答案:

没有答案