错误: 程序包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

在这里插入图片描述

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