錯誤: 程序包android.support.annotation不存在(最新最具體2019年11月18日)

網上看到很多帖子,都是寫一半,不夠具體,或不適配,我自己嘗試了很多,最後得到的解決。

前提條件

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.
在這裏插入圖片描述

同步項目 Sync

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章