版權聲明:本文為HaiyuKing原創文章,轉載請注明出處!
前言
這里簡單記錄下在開發的時候使用的Android Studio開發環境版本以及相關注意事項。
一般來講,每隔一段時間就要檢查下Android Studio的穩定版本,以便使用最新版本的Android Studio。
比如,目前我使用的Android Studio開發環境配置:
Android Studio版本:3.2【20181027已升級到3.2.1】
Android SDK Tools版本:26.1.1
Android Platform Tool版本:28.0.1
Android Platform Version:API28:Android 9.0(pie)revision 6
Android Gradle Plugin版本:3.2.0【20181027已升級到3.2.1】
Gradle發行版本:4.6
Android SDK Build Tools:28.0.3
至於在Android Studio中如何查找上面的版本號信息,請閱讀下面提到的參考資料或者看截圖,我這里就不重復說明了。
檢查Android Studio版本,升級到新版本
翻.牆【我使用的是藍燈,下載地址:https://github.com/getlantern/lantern/releases/tag/latest】。
參考《【Android Studio安裝部署系列】三十、從Android studio2.2.2升級到Android studio3.0之路》
《【Android Studio安裝部署系列】三十一、從Android studio3.0.0升級到Android studio3.0.1》
《【Android Studio安裝部署系列】三十五、從Android studio3.0.1升級到Android studio3.1.4【以及創建android p模擬器的嘗試(未成功)】》
《【Android Studio安裝部署系列】三十六、從Android Studio3.1.4升級到Android studio3.2【以及創建android p模擬器(未成功)】》
查看Android Studio版本號信息
File——Settings——Appearance & Behavior——System Settings——Updates

=====20181027已升級=====

查看並更新SDK Tool、SDK Build Tool、Platform Tool版本
參考《【Android Studio安裝部署系列】二十四、Android studio中Gradle插件版本和Gradle版本關系》
《【Android Studio安裝部署系列】三十六、從Android Studio3.1.4升級到Android studio3.2【以及創建android p模擬器(未成功)】》
查看

新建一個HelloWorld空項目
此時會自動下載最新版本的gradle。

項目的build.gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
=====20181027升級=====
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app的build.gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.why.project.helloworld"
minSdkVersion 16 targetSdkVersion 28
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:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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-wrapper.properties文件
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
打開一個舊項目
一般情況下會彈出這樣一個對話框:

可以更新也可以不更新,看具體實際情況吧。
=====20181027升級=====

附錄
這里講一下當gradle升級到4.4的時候,需要注意將build.gradle文件中引用jar文件的舊代碼:
compile files('libs/umeng-analytics-7.5.3.jar')
修改成
api files('libs/umeng-analytics-7.5.3.jar')
api 指令
完全等同於compile指令,沒區別,你將所有的compile改成api,完全沒有錯。
implement指令
這個指令的特點就是,對於使用了該命令編譯的依賴,對該項目有依賴的項目將無法訪問到使用該命令編譯的依賴中的任何程序,也就是將該依賴隱藏在內部,而不對外部公開。
參考《android gradle tools 3.X 中依賴,implement、api 指令》、《android studio 3.1 升級gradle4.4時所踩到的坑》、《Invoke-customs are only supported starting with android 0 --min-api 26》
參考資料
