网上看到很多帖子,都是写一半,不够具体,或不适配,我自己尝试了很多,最后得到的解决。

前提条件

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

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐