There are many different versions of Android development, such as compileSdkVersion
, , minSdkVersion
, targetSdkVersion
and the versions that rely on third-party libraries in the project. Different modules and different developers have different versions, so a unified version specification file is needed. Now I will introduce it. a method.
In the root directory of the project, that is, the build.gradle file (build.gradle of the project) in the same directory as the app, as shown in the figure below
Add the following groovy code at the end.
ext {
// Sdk and tools
compile_sdk_version = 26
build_tools_version = '26.0.0'
min_sdk_version = 14
target_sdk_version = 22
version_code = 100900900
version_name = '1.9.9'
// App dependencies
support_version = '26.1.0'
leakcanary_version = '1.5.4'
junit_version = '4.12'
robolectric_version = '3.1.2'
}
With this specification, our build.gradle file under the app can be referenced like this
android {
compileSdkVersion compile_sdk_version
defaultConfig {
minSdkVersion min_sdk_version
versionCode version_code
versionName version_name
}
}
dependencies {
compileOnly "com.android.support:appcompat-v7:$support_version"
compileOnly "com.android.support:design:$support_version"
testImplementation "junit:junit:$junit_version"
testImplementation "org.robolectric:robolectric:$robolectric_version"
testImplementation "com.android.support:support-v4:$support_version"
}
Is it once and for all? To modify the version in the future, you only need to modify the build.gradle file in the root directory to modify all dependent versions. I hope it can help your Android development specifications.