Android Studio同时添加了@ androidx.annotation和@ android.support.annotation问题 [英] Android Studio adds both @androidx.annotation and @android.support.annotation problem

查看:723
本文介绍了Android Studio同时添加了@ androidx.annotation和@ android.support.annotation问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Android Studio更新到了3.2.0版.

I updated Android Studio to version 3.2.0.

当我接受来自建议列表 alt +输入的任何更改.

When I accept any change from list of suggestion or alt + enter.

  • 问题是@androidx.annotation自动创建的.
  • 因此,建议方法具有两个注释@androidx.annotation.Nullableandroid.support.annotation.Nullable.
  • 我不想手动删除此不必要的建议,所以只有android.support.annotation怎么办?
  • androidx.annotation程序包也未添加到我的应用程序中.而且我不想添加 androidx.annotation .
  • Problem is @androidx.annotation auto created.
  • Thus suggestions method have two annotation @androidx.annotation.Nullable and android.support.annotation.Nullable.
  • I don't want to manually remove this unwanted suggestion, so what can I do to have only android.support.annotation?
  • Also androidx.annotation package is not added in my app. and I don't want to add 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的自动生成?

Is there some IDE setting to remove auto generation of androidx.annotation?

我可以通过从官方迁移到androidx( rel ="noreferrer"> doc ),但目前无法将所有项目迁移到androidx.所以需要一个解决方案.

I could get rid of this problem with migrating to androidx (from official doc), but I am not able to migrate all projects to androidx currently. So need a solution.

推荐答案

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

AndroidX is the new extension libraries for backward compatibility support. In future new feature backward compatibility support will be addressed in AnddroidX. As stated in this blog https://android-developers.googleblog.com/2018/05/hello-world-androidx.html

28.0.0的稳定版本将是打包为> android.support的最终功能版本.所有后续功能版本将仅以> androidx打包的工件形式提供.

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-库/修订版

修订28.0.0生产 (2018年9月21日)

Revision 28.0.0 Production (September 21, 2018)

这是Support Library 28.0.0的稳定版本,适合在生产中使用.这将是> android.support包装下的最后一个功能版本,建议开发人员迁移到> AndroidX.

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插件3.2.0-alpha14自动应用的,它重写了JAR和AAR依赖关系(以及传递性依赖关系)的字节码和资源,以引用新的androidx打包的类和工件.我们还将提供独立的翻译工具JAR.

If you depend on a library that references the older Support Library, Android Studio will update that library to reference androidx instead via dependency translation. Dependency translation is automatically applied by the Android Gradle Plugin 3.2.0-alpha14, which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts. We will also provide a standalone translation tool as a JAR.

因此,在第1步(依赖关系转换)中::在gradle.properties文件中,将 android.useAndroidX 标志设置为true,并将 android.enableJetifier 标记为true.

So, In Step 1(dependency translation): In your gradle.properties file set the android.useAndroidX flag to true and the android.enableJetifier flag to true.

android.useAndroidX=true
android.enableJetifier=true

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

in Step 2(source refactoring): With Android Studio 3.2 and higher, you can quickly migrate an existing project to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

这篇关于Android Studio同时添加了@ androidx.annotation和@ android.support.annotation问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆