Java 类型 `javax.inject.Inject` 由多个托管类型生成。请更改 [注册] 属性
Posted
技术标签:
【中文标题】Java 类型 `javax.inject.Inject` 由多个托管类型生成。请更改 [注册] 属性【英文标题】:The Java type `javax.inject.Inject` is generated by more than one managed type. Please change the [Register] attribute 【发布时间】:2022-01-22 14:30:50 【问题描述】:已将 Xamarin.android 项目迁移到 AndroidX,并且必须更新一些包。现在我无法构建我的项目并收到以下错误消息:
`javax.inject.Named` generated by: JavaX.Inject.INamed, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
`javax.inject.Scope` generated by: Javax.Inject.IScope, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
`javax.inject.Qualifier` generated by: JavaX.Inject.IQualifier, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Java type `javax.inject.Inject` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
`javax.inject.Provider` generated by: JavaX.Inject.IProvider, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
`javax.inject.Inject` generated by: JavaX.Inject.IInject, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
`javax.inject.Qualifier` generated by: Javax.Inject.IQualifier, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Java type `javax.inject.Provider` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
`javax.inject.Scope` generated by: JavaX.Inject.IScope, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
`javax.inject.Named` generated by: Javax.Inject.INamed, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Java type `javax.inject.Scope` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
`javax.inject.Provider` generated by: Javax.Inject.IProvider, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
`javax.inject.Singleton` generated by: JavaX.Inject.ISingleton, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
`javax.inject.Inject` generated by: Javax.Inject.IInject, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Java type `javax.inject.Named` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
The Java type `javax.inject.Qualifier` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
`javax.inject.Singleton` generated by: Javax.Inject.ISingleton, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Java type `javax.inject.Singleton` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
请告知如何修复它或如何更改 [Register] 属性以及需要在哪里完成。我无法删除这些包,其他包依赖于它们。
【问题讨论】:
可能无济于事,但是在进行这样的重大更改后,退出 VS,删除解决方案中的所有 bin 和 obj 文件夹。 @ToolmakerSteve 试过了,没有帮助。 项目中的nuget包之间存在一些冲突。在每个错误行上查看“生成者”之后的包名称对。也许必须删除一些包,需要一个不同的包才能与 AndroidX 一起使用。不幸的是,确切的修复需要知道哪些包冲突。在新文件夹中创建一个新的空项目。开始添加您需要的 nuget。一次一个。在添加每个之后构建。直到你再次出错。然后添加以质疑您添加的包,以及新的错误列表。 @ToolmakerSteve 谢谢,从项目中删除所有包并重新添加它们。它解决了这个问题。 【参考方案1】:在 migration 之后,我们需要对工具未涵盖的场景进行一些手动命名空间更改。
AndroidX 替换了 Android support libraries
,因此任何对 Android 支持库类型的引用都必须替换为对 AndroidX 类型的引用。
下表显示了命名空间的变化
Android support library namespace | AndroidX namespace |
---|---|
Android.Support.V4.App | AndroidX.Core.App |
Android.Support.V4.Content | AndroidX.Core.Content |
Android.Support.V4.App | AndroidX.Fragment.App |
Android.Support.V7.App | AndroidX.AppCompat.App |
Android.Support.V7.Widget | AndroidX.AppCompat.Widget |
更多:https://github.com/xamarin/AndroidX/blob/main/mappings/androidx-class-mapping.csv.
更多详情请参考链接:
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/troubleshooting/questions/forms5-migration#use-androidx-types
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/android/androidx-migration
更新
删除所有包并在项目中重新添加。
【讨论】:
谢谢,我已经更改了命名空间名称。为了解决这个问题,我必须从项目中删除所有包并重新添加它们。以上是关于Java 类型 `javax.inject.Inject` 由多个托管类型生成。请更改 [注册] 属性的主要内容,如果未能解决你的问题,请参考以下文章