版權聲明:本文爲HaiyuKing原創文章,轉載請註明出處!android
本Demo採用的是其中一個方案,其餘方案請閱讀參考資料《Android Studio中統一管理版本號引用配置》git
注意事項:github
一、 導入類文件後須要change包名以及從新import R文件路徑app
二、 Values目錄下的文件(strings.xml、dimens.xml、colors.xml等),若是項目中存在,則複製裏面的內容,不要整個覆蓋maven
其中,buildToolsVersion的可選值在sdk安裝目錄下的build-tools中查看(對了,若是使用AS3.0.1新建項目,可能在app/build.gradle文件中看不到buildToolsVersion,那麼最後可加可不加,本Demo就不添加了):ide
新建項目後的app/build.gradle文件:工具
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.why.project.androidcnblogsdemo"
minSdkVersion 16 targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
//Android Studio統一管理依賴版本號引用配置 ext { //修改compileSdkVersion並不會影響咱們的咱們生成的app在手機先的行爲。最理想的狀況就是把compileSdkVersion設置到最高。 globalCompileSdkVersion = 27 //構建工具的版本號是多少,規則是能夠用高的構建工具來構建低版本Sdk的工程。使用build-tools目錄中的最大版本號便可 globalBuildToolsVersion = "27.0.3" //targetSdkVersion的設置主要是當系統版本高於設置的target的時候。而後targetSdkVersion最好和compileSdkVersion同樣。 globalTargetSdkVersion = 27 //這個就是程序運行的最低的要求的Sdk版本號,在低於這個版本號的手機設備上沒法安裝。 globalMinSdkVersion = 16 supportLibraryVersion = "27.1.1" /*=================================經常使用的引用============================================*/ //supportLibVersion 的頭數字是和targetSdkVersion 版本同樣的。 androidDependencies = [ appcompat_v7 : "com.android.support:appcompat-v7:${supportLibraryVersion}", design : "com.android.support:design:${supportLibraryVersion}", support_v4 : "com.android.support:support-v4:${supportLibraryVersion}", recyclerView : "com.android.support:recyclerview-v7:${supportLibraryVersion}", ] /*=================================module中公共用到的引用============================================*/ globalDependencies = [ //constraintLayout引用 constraintLayout : "com.android.support.constraint:constraint-layout:1.1.2", //glide的引用 glide : "com.github.bumptech.glide:glide:4.7.1", ] }
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.globalCompileSdkVersion
defaultConfig {
applicationId "com.why.project.androidcnblogsdemo"
minSdkVersion rootProject.ext.globalMinSdkVersion
targetSdkVersion rootProject.ext.globalTargetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation androidDependencies.appcompat_v7 implementation globalDependencies.constraintLayout
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
無gradle
如何查看buildToolsVersion的版本google