1. 程式人生 > >Android Studio 從 2.3 升級到3.2

Android Studio 從 2.3 升級到3.2

Android Studio 從 2.3 升級到3.2以後,對於舊工程的引入,需要如下處理:

  1. 工程下的引入studio 版本和 gradle 的版本需要跟進,如studio 3.2.1和gradle 4.6:
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
}

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
  1. project的build.gradle檔案中刪除
1)classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
	module的build.gradle檔案中刪除
2)apply plugin: 'com.neenbedankt.android-apt'
	module的build.gradle檔案中替換
3)//apt 'com.jakewharton:butterknife-compiler:8.0.1'
	annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'
  1. buildVersionCode 可以刪除掉
    高版本中,buildVersionCode可以省略不些,系統會自動選用合適的版本進行編譯。
  2. compile 相關關鍵詞替換
Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'.
Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation' and 'androidTestApi'.
Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'.
Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.

‘implementation’ and 'api’的區別,詳情可參考連結 https://www.jianshu.com/p/8962d6ba936e
這是因為implementation只能用於當前的module,倘若在庫中用這種方式設定依賴,我們在app的module就引用不到。但是api可以。
6. All flavors must now belong to a named flavor dimension.

在主app的build.gradle裡面的
defaultConfig {
	targetSdkVersion:***
	minSdkVersion :***
	versionCode:***
	versionName :***
	//版本名後面新增一句話,意思就是flavor dimension 它的維度就是該版本號,這樣維度就是都是統一的了
	flavorDimensions "versionCode"
}

PS:升級後會遇到各種問題,一定要儘量正確解決問題,否則可能會出現錯誤方式導致的錯誤問題,最終導致無解。。。