Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify common string for version in build.gradle?

I have a build.gradle that has following content:-

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'

How can I specify the version number (here 25.3.1) at a common place and reuse it every where, so that when ever I need to change it, I have to change it at only one place?

like image 573
Sreekanth Karumanaghat Avatar asked Jan 03 '23 21:01

Sreekanth Karumanaghat


1 Answers

You can use Gradle features to achieve this.

ext {
    supportVersion = "25.3.1"
}

dependencies {
    compile "com.android.support:appcompat-v7:$supportVersion"
    compile "com.android.support:design:$supportVersion"
    compile "com.android.support:cardview-v7:$supportVersion"
    compile "com.android.support:recyclerview-v7:$supportVersion"
}

See also:

  • https://docs.gradle.org/3.3/userguide/writing_build_scripts.html
like image 80
shiftpsh Avatar answered Jan 06 '23 10:01

shiftpsh