I recently switched from Eclipse to Android Studio (for test purposes) with an production project and it feel really great. I like the gradle way very much.
In Android Studio the project structure looks (simplified) something like this
+RandomProject
|-+Random
| |- build.gradle (lets call it build2)
| |- [...]
|- build.gradle (lets call it build1)
|- [..]
The build1 file has the following content by default:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
I wonder if its possible/a good practice to specify the versionName and versionCode in that (build1) file, so that it is going to be "inherited" to the build2 file. (and if so, how?)
Thanks for the input.
As you may know, on android you have to define two version fields for an app: the version code (android:versionCode) and the version name (android:versionName). The version code is an incremental integer value that represents the version of the application code.
You can do this by adding extra properties to the ext block in the top-level build.gradle file. // of properties you can define. // You can also create properties to specify versions for dependencies.
To change its path go to this path File > Settings... > Build, Execution, Deployment > Gradle In the Global Gradle settings Change Service directory path to what you want. Save this answer.
You can do it with ExtraPropertiesExtension.
RandomProject\build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
ext.compileSdkVersion=19
ext.buildToolsVersion="19"
ext.versionName="1.0.7"
ext.versionCode=7
RandomProject\Random\build.gradle
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
versionName rootProject.versionName
versionCode rootProject.versionCode
}
}
The New Build System site now has a tip about this. It's similar to Sergii's answer, but subtly different:
In the root project's build.gradle:
ext {
compileSdkVersion = 19
buildToolsVersion = "19.0.1"
}
in all the android modules:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
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