Gradle Unified Management Version number reference configuration
In order to improve project development efficiency, some open source frameworks are often introduced in the actual project development process, as well as the various module used in the project ,moudle Too much time is best to provide a unified way to manage version numbers, such as:compilesdkversion,buildtoolsversion, Androidtestcompile and so on, to facilitate future maintenance of the version number, here Records 2 ways to deal with the above problems.
Way One
1 . Create a. gradle file under the project root directory , such as:config.gradle
2. Introduce the configuration file we created in the Build.gradle file in the root directory
3. The contents of the file in Config.gradle can be defined by itself, such as the following example:
ext { //SDK version compile_sdk_version =/ /For Gradle compiled project version build_tools_version = "24.0.2" Minimum supported Android version Min_sdk_version =/ /target version Target_sdk_version =/ /Set whether to use confusion minify_enabled = True minify_disabled = False //application package name application_id = ' com.mainiway.eworkpal ' //Version of ' Com.android.support:appcompat-v7 ", refer it as Folow: // compile" com.android.support:appcompat-v7:${ Appcompat_version} " appcompat_version = ' 23.2.1 '}
4. use in Build.gradle in the app directory
dependencies { compile filetree (include: [' *.jar '], dir: ' Libs ') compile "com.android.support:cardview-v7:${ Appcompat_version} " compile" com.android.support:appcompat-v7:${appcompat_version} " compile" Com.android.support:design:${appcompat_version} " compile ' com.github.bumptech.glide:glide:3.7.0 '}
Way Two (recommended)
1. in the root directory under the Build.gradle file, add the contents of the ext{ ....
Top-level build file where can add configuration options common to all Sub-projects/modules.buildscript { repos itories { jcenter () } dependencies { classpath ' com.android.tools.build:gradle:2.2.3 ' //NOTE: Do not place your application dependencies here; They belong //In the individual module Build.gradle files }}allprojects { repositories { jcenter () maven {URL "Https://jitpack.io"}} } Task Clean (type:delete) { Delete rootproject.builddir}//Define versions. A single Placeext { //SDK and Tool s minsdkversion = targetsdkversion = compilesdkversion = buildtoolsversion = ' 24.0.2 ' //dependencies supportlibraryversion = ' 23.2.1 '}
2. Use the $rootProject in Build.gradle in the app directory . Supportlibraryversion
Apply plugin: ' Com.android.application ' android { compilesdkversion compile_sdk_version buildtoolsversion Build_tools_version defaultconfig { applicationid application_id minsdkversion min_sdk_version targetsdkversion target_sdk_version versioncode 1 versionname "1.0" }}dependencies { Compile Filetree (include: [' *.jar '], dir: ' Libs ') compile "com.android.support:cardview-v7:$ Rootproject.supportlibraryversion " compile" com.android.support:appcompat-v7:$ Rootproject.supportlibraryversion " compile" com.android.support:design: $rootProject. Supportlibraryversion " }
"Reprint Annotated Gao_chun's blog:http://blog.csdn.net/gao_chun/article/details/58105089"
Gradle Unified Management Version number reference configuration in Android Studio