Skip to content
Advertisement

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

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. Just like a pre-processor macros in C/C++…

An example of declaration would be something like that … :

JavaScript

Is there a way to do something like that ?

Advertisement

Answer

Here are two ways to pass value from Gradle to use in Java;

Generate Java Constants

JavaScript

You can access them with BuildConfig.FOO

Generate Android resources

JavaScript

You can access them in the usual way with @string/app_name or R.string.app_name

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement