網上看到很多帖子,都是寫一半,不夠具體,或不適配,我自己嘗試了很多,最後得到的解決。
前提條件
Android studio 3.5.1
jdk 1.8
com.android.tools.build:gradle:3.5.1
項目遷移到androidx
第一步:查看build.gradle是否配置
搜索build.gradle中是否有關鍵字com.android.support:support-annotations
假如沒有,需要添加配置,步驟如下如圖
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:support-annotations:28.0.0"
}
修改報錯文件
查看存在報錯的文件,修改導入包。
import android.support.annotation.IntDef;
import android.support.annotation.WorkerThread;
import androidx.annotation.IntDef;
import androidx.annotation.WorkerThread;
快捷操作
Ctrl + Shift + R
import android.support.annotation.
替換爲
import androidx.annotation.