Search code examples
xamarinxamarin.formsxamarin.androidandroidx

The Java type `javax.inject.Inject` is generated by more than one managed type. Please change the [Register] attribute


Migrated Xamarin.Android project to AndroidX and had to update some packages. Now I am unable to build my project and getting following error messages:

`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.                

Please advice how it can be fixed or how can I change the [Register] attribute and where it needs to be done. I cannot remove those packages, other packages depend on them.


Solution

  • After the migration , we'll need to make some manual namespace changes for scenarios the tool doesn't cover.

    AndroidX replaces the Android support libraries , and so any references to Android support library types must be replaced with references to AndroidX types.

    The following table shows the namespace changes

    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

    More : https://github.com/xamarin/AndroidX/blob/main/mappings/androidx-class-mapping.csv.

    Refer to the links for more details :

    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/troubleshooting/questions/forms5-migration#use-androidx-types

    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/platform/android/androidx-migration

    Update

    Delete all the packages and re-add them in projects.