I'm using AndroidStudio and I have the following:
I want to set up my "communication" module's gradle file to achieve the following:
As app module's gradle, I can setup variables for BuildConfig.java file, e.g.:
buildTypes {
release {
...
buildConfigField "String", "SERVER_URL", '"my_url"'
}
debug {
buildConfigField "String", "SERVER_URL", '"my_url"'
}
}
and then I can use them using BuildConfig.SERVER_URL
The question is: How do I achieve this using a Java Library module?
BuildConfig. java is generated automatically by Android build tools, and is placed into the gen folder.
In recent versions of the Android Developer Tools (ADT) for Eclipse, there's a class called BuildConfig which is automatically generated by the build. This class is updated automatically by Android's build system (like the R class), and it contains a static final boolean called DEBUG, which is normally set to true.
There's a class called BuildConfig. java which is automatically generated by the build system. This class is updated automatically by Android's build system (like the R class). It already contains a static final boolean called DEBUG, which is normally set to true.
The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.
I think that you are looking for this Gradle plugin. It brings BuildConfig to pure Java module.
https://github.com/mfuerstenau/gradle-buildconfig-plugin
If by Java library you mean Android module then :
Set buildTypes variables inside the build.gradle
file into library module like app module.
Get it by using the correct BuildConfig Class.
my.package.app.BuildConfig.APP_VARIABLE
my.package.library.BuildConfig.LIBRARY_VARIABLE
In other way, maybe you can take a look to gradle task and System Environment this answer can help you https://stackoverflow.com/a/25714617/4681367
There is no other way to get build configuration outside an Android module.
Just set/add an environment variable based on your android BuildConfig variables.
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