我有一个build.gradle,其中包含以下内容: -
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'
如何在一个公共场所指定版本号(此处为25.3.1)并在每个地方重复使用,以便在需要更改时,我必须在一个地方更改它?
答案 0 :(得分:4)
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:
答案 1 :(得分:1)
In Project level gradle, you specify the version code. If we specify version code in project level then we can use that version in all modules. For example, we had three modules in a project. If we specify version code in project level then easily use that in module level gradle file.
ext {
appcompatVersion = '25.3.1'
supportDesignVersion = '25.3.1'
cardviewVersion = '25.3.1'
recyclerviewVersion = '25.3.1'
}
In Module level gradle, you use it like below:
dependencies {
compile 'com.android.support:appcompat-v7:$appcompatVersion'
compile 'com.android.support:design:$supportDesignVersion'
compile 'com.android.support:cardview-v7:$cardviewVersion'
compile 'com.android.support:recyclerviewv7:$recyclerviewVersion'
}
答案 2 :(得分:0)
In the project gradle file add the variable
buildscript {
ext.supportLibraryVersion = "25.3.1"
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
........
And in the app gradle file refer the variable created.
dependencies {
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:design:$supportLibraryVersion"
for more reference follow this link