错误: 程序包android.support.annotation不存在(最新最具体2019年11月18日)

  • Post author:
  • Post category:其他


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



前提条件

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

在这里插入图片描述



版权声明:本文为qq471208499原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。