本文介绍了有没有一种方法可以根据选定的productFlavor更改Gradle变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的gradle示例:我想根据选定的productFlavors动态更改STORE_FILE_PATH值.当前,STORE_FILE_PATH始终使用最后定义的productFlavor覆盖其值. (在我的情况下,它始终变为"/pro.jks")

Below is my gradle example:I want to change STORE_FILE_PATH value dynamically based on selected productFlavors. Currently STORE_FILE_PATH is always overwriting it's value with last defined productFlavor. (In my case it always becomes "/pro.jks")

帮我找到解决方法.谢谢

Help me find solution. Thanks

def STORE_FILE_PATH = "";

android {
    productFlavors {
        free {

            versionCode 1
            versionName "1.0.0"

            applicationId "com.example.free"

            buildConfigField "boolean", "IS_AD_ENABLED", "true"
            STORE_FILE_PATH = "/free.jks"

        }


        pro {

            versionCode 1
            versionName "1.0.0 pro"

            applicationId "com.example.pro"

            buildConfigField "boolean", "IS_AD_ENABLED", "false"

            STORE_FILE_PATH = "/pro.jks"
        }

    }

    signingConfigs {
        signingConfig {
            keyAlias 'aa'
            keyPassword '123'
            storeFile file (STORE_FILE_PATH)
            storePassword '123'
        }
    }
}

推荐答案

您应该定义多个signingConfig,并在不同的productFlavors中使用它

You should define multiple signingConfigs and use it in different productFlavors

signingConfigs{
   freeKey{}
   proKey{}
}

productFlavors {
    free {

        versionCode 1
        versionName "1.0.0"

        applicationId "com.example.free"

        buildConfigField "boolean", "IS_AD_ENABLED", "true"
        signingConfig signingConfigs.freeKey
    }


    pro {

        versionCode 1
        versionName "1.0.0 pro"

        applicationId "com.example.pro"

        buildConfigField "boolean", "IS_AD_ENABLED", "false"

        signingConfig signingConfigs.proKey
    }

}

这篇关于有没有一种方法可以根据选定的productFlavor更改Gradle变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 11:38