I have a project in Android Studio with a couple of modules.
app module. With apply plugin: 'com.android.application'.androidLibrary module. With apply plugin: 'com.android.library'.javaLibrary module. With apply plugin: 'java'.I want to declare some variables in the project gradle.properties file and be able to read them from the javaLibrary module.
I have declared the properties in the following ways according this documentation...
mysuperhost=superhostsystemProp.mysuperhost=superhostORG_GRADLE_PROJECT_mysuperhost=superhostorg.gradle.project.mysuperhost=superhost... and tried to read them this way with no success:
System.getenv("mysuperhost");System.getProperty("mysuperhost");I know how to read properties from the BuildConfig class, but this is a generateed class in the app module (with apply plugin: 'com.android.application'), so this does not work for this particular case.
If you have some value inside of the your gradle.properties file like mysuperhost=superhost then write the following lines in the your build.gradle file (to grab property from gradle.properties file and add it into BuildConfig.java class):
// ...
// ...
android {
// Just for example
compileSdkVersion 23
// Just for example
buildToolsVersion "23.0.2"
// ...
// ...
defaultConfig {
// Just for example
minSdkVersion 14
// Just for example
targetSdkVersion 23
// This is the main idea
buildConfigField('String', 'MY_SUPER_HOST', "\"${mysuperhost}\"")
// ...
// ...
}
// ...
// ...
}
// ...
// ...
After that build your project and you are able to use your value via BuildConfig.MY_SUPER_HOST
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With