I been developing Android apps for a while now, but came to the realization that I still don't know what the gradle.properties
file is used for.
I've read a bit through the Gradle documentation which explains that you can add configurations for specifying the Java home, or memory settings, for example. Is there anything else it can be used for?
My main reference for times like this is usually the Google I/O open-source app, and looking at its gradle.properties
file, I can see that one use of it is to store dependency version variables, so the version codes for the Android Support library dependencies, for example, don't each need to be updated with a new release of the library, just that one variable can be updated:
...
// Android support libraries.
compile "com.android.support:appcompat-v7:${android_support_lib_version}"
compile "com.android.support:cardview-v7:${android_support_lib_version}"
compile "com.android.support:design:${android_support_lib_version}"
compile "com.android.support:support-v13:${android_support_lib_version}"
compile "com.android.support:recyclerview-v7:${android_support_lib_version}"
compile "com.android.support:preference-v7:${android_support_lib_version}"
...
The same idea has been used for Google Play services.
However, in one of my own Android projects, I have been doing something similar - I put my version variable in the root build.gradle
file like so:
// Top-level build file where you can add configuration options
// common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.0.5-2'
repositories {
...
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
...
Then I've been using it in my module build.gradle
like so:
dependencies {
...
// Kotlin standard library
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
...
}
So I guess I have a couple questions:
What else is the
gradle.properties
file used for?What is the difference between using an external variable for dependency versions in
gradle.properties
(as in iosched), vs an external variable in the rootbuild.gradle
(as I have been doing)?- Which is the preferred method, if there is one?
- Are there advantages/disadvantages to doing it one particular way?