Is it possible to declare a variable in Gradle usable in Java?

后端 未结 9 1244
春和景丽
春和景丽 2020-11-22 09:11

Is it possible to declare a variable in Gradle usable in Java ? Basically I would like to declare some vars in the build.gradle and then getting it (obviously) at build time

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 09:26

    rciovati's answer is entirely correct I just wanted to add one more tidbit that you can also create variables for every build type within the default config portion of your build.gradle. This would look like this:

    android {
        defaultConfig {
            buildConfigField "String", "APP_NAME", "\"APP_NAME\""
        }
    }
    

    This will allow you to have access to through

    BuildConfig.App_NAME
    

    Just wanted to make a note of this scenario as well if you want a common config.

提交回复
热议问题