因新版的Android Studio一直彈出提示要更新,Android Gradle Plugin也一直有更新提示,查看了一下新的開發環境好似有了重大的變化,連版本號都看得出來有著大躍進,都要更新了就直上最新的Release版吧~雖然未知的領域很可怕,但該備份的也都備份好了,就來試試看
將專案的內建函式庫合併成新的androidX,這時候不得不說Android Studio很貼心,有個一鍵轉移成androidX的功能
點擊後會彈出視窗
接著會在下方的Find出現所有會因為此更新影響的檔案,然後點擊Do Refactor
出現進度條,稍待更新
更新完成後會發現原本android.support的函式庫都被換成了androidX為首的函式庫
然後點擊”File”>”Project Structure…”
更新一下java版本(從1.7改成1.8),同步完
執行編譯,發現有報錯
而Android Gradle Plugin Version和Gradle Version的部分
假如要更新到新版,就要升級Android Studio版本
於是將版本從4.1.2更新成Arctic Fox | 2020.3.1
將Android Gradle Plugin Version更新為7.0.2
將Gradle Version更新為7.0.2
然後編譯後出現此錯誤
我將java1.8 改為11後
還是出現
然後出現下面的警告與錯誤
警告:
* DSL element 'dexOptions' is obsolete and should be removed. It will be removed in version 8.0 of the Android Gradle plugin. Using it has no effect, and the AndroidGradle plugin optimizes dexing automatically.
* Using flatDir should be avoided because it doesn't support any meta-data formats.
錯誤:
* API 'BaseVariant.getApplicationIdTextResource' is obsolete and has been replaced with 'VariantProperties.applicationId'. It will be removed in version 7.0 of the Android Gradle plugin. For more information, see TBD. To determine what is calling BaseVariant.getApplicationIdTextResource, use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
* Some problems were found with the configuration of task ':app:processCa88asiaDebugGoogleServices' (type 'GoogleServicesTask').
先解決錯誤
將專案的依賴項的google 服務更新成最新版
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2’
classpath 'com.google.gms:google-services:4.2.0'
}
更新版本為4.3.8
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.google.gms:google-services:4.3.8'
}
接著處理警告一* DSL element 'dexOptions' is obsolete and should be removed. It will be removed in version 8.0 of the Android Gradle plugin. Using it has no effect, and the AndroidGradle plugin optimizes dexing automatically.
找到下列的項目?內容?
dexOptions {
dexInProcess true
preDexLibraries true
javaMaxHeapSize "4g"
}
刪除以上內容即可
繼續處理警告二* Using flatDir should be avoided because it doesn't support any meta-data formats.
於儲存庫中找到下列指令
flatDir {
dirs 'libs'
}
刪除以上指令,於”android”項下調整添加下列指令即可
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
以上更新完成,也清掉警告和錯誤了~下一篇針對jcenter即將落日後的舊專案調整做解說~