Android Studio添加了@ androidx.annotation和@ android.support.annotation问题

我将Android Studio更新到版本3.2.0.

当我接受建议列表中的任何更改或alt输入.

>问题是@ androidx.annotation自动创建.
>因此,建议方法有两个注释@ androidx.annotation.Nullable和android.support.annotation.Nullable.
>我不想手动删除这个不需要的建议,所以我该怎么做只有android.support.annotation?
>我的应用程序中也没有添加androidx.annotation包.我不想添加androidx.annotation.

见例子.

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {
    @Override
    public void onCreate(@androidx.annotation.Nullable @Nullable Bundle savedInstanceState, @androidx.annotation.Nullable @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }
}

是否有一些IDE设置来删除androidx.annotation的自动生成

更新

我可以通过迁移到androidx(from official doc)摆脱这个问题,但我目前无法将所有项目迁移到androidx.所以需要一个解决方

解决方法:

AndroidX是用于向后兼容性支持的新扩展库.将来,新功能向后兼容性支持将在AnddroidX中得到解决.正如本博客https://android-developers.googleblog.com/2018/05/hello-world-androidx.html所述

The stable release of 28.0.0 will be the final feature release packaged as >android.support. All subsequent feature releases will only be made available as >androidx-packaged artifacts.

https://developer.android.com/topic/libraries/support-library/revisions

Revision 28.0.0 Production
(September 21, 2018)

This is the stable release of Support Library 28.0.0 and is suitable for use >in production. This will be the last feature release under the >android.support packaging, and developers are encouraged to migrate to >AndroidX.

将您的应用程序从android.support移动到androidx打包的依赖项

请参阅此链接,https://developer.android.com/jetpack/androidx/migrate

如果您依赖于引用旧支持库的库,Android Studio将通过依赖项转换更新该库以引用androidx.依赖转换由Android Gradle Plugin 3.2.0-alpha14自动应用,它重写了JAR和AAR依赖项(和传递依赖项)的字节码和资源,以引用新的androidx打包的类和工件.我们还将提供独立的翻译工具作为JAR.

因此,在步骤1(依赖项转换)中:在gradle.properties文件中,将android.useandroidX标志设置为true,将android.enableJetifier标志设置为true.

android.useandroidX=true
android.enableJetifier=true

在第2步(源重构):使用Android Studio 3.2及更高版本,您可以通过选择Refactor>快速迁移现有项目以使用AndroidX.从菜单栏迁移到AndroidX.

Refactor to Androidx from menu

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...