-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing: Type XYZ is defined multiple times
|| packages generated by more than one managed type
#764
Comments
Type XYZ is defined multiples times
|| packages generated by more than one managed type
Type XYZ is defined multiple times
|| packages generated by more than one managed type
Type XYZ is defined multiple times
|| packages generated by more than one managed type
Type XYZ is defined multiple times
|| packages generated by more than one managed type
We have a Xamarin.Forms app and given that we're having several issues upgrading to MAUI we decided to give a try upgrading the platforms (Android & iOS) to .NET 7 and check how it goes. However, I'm having this issue on the Android project on .NET 7 and tried all the proposed solutions/workarounds but still getting the error on
Installed packages: <PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Xamarin.AndroidX.AutoFill" Version="1.1.0.18" />
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.10.1.2" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.6.1.3" /> Is there anything else we could try? Edit: Tried also on .Net 8 preview 6 and getting the same issue. And tried the previous version of the |
@fedemkr I will create minimal repro sample on Sunday. Looking good: https://www.nuget.org/packages/Xamarin.AndroidX.AutoFill/1.1.0.18 Cannot repro with |
@fedemkr It looks like you are using both Android Support Libraries and AndroidX:
It is highly recommended to migrate away from Android Support Libraries, as Google deprecated and stopped developing them many years ago. In .NET 6+, we no longer run the Android Support -> AndroidX migration automatically for you. To make it run, add a reference to the |
Looks like it was really late and I missed details in this error:
I will use stronger words - one MUST get rid of Android.Support - for own sanity. It is old and unsupported and probably tons of security and other issues. |
Don't use:
It is built into .NET MAUI: https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/platform-helpers?tabs=android |
Didn't know that. I just checked date of the latest release and it is 2018-05. I didn't dive into dependencies and it does not have any, so it should be OK, because it does not pull in transitive dependencies. I think in this case the problem is with mixing Android.Support and AndroidX as jpobst stated. But to be sure I would need to dive in deeper into dependency graph/tree/forest. |
This is happening after updating Plugin.LocalNotification to the latest 11.1.4.
.NET MAUI building on MacOS with latest MAUI workloads and using the latest packages.
|
In this case: updating to the newest versions is causing errors.This works great!
This fails to build.
with
|
<PackageReference Include="Xamarin.Firebase.Perf" Version="121.0.1.1" /> to a blank net8.0 android app also produces similar error:
By adding the line below the error is gone, however i doubt if it's a correct workaround <PackageReference Include="Xamarin.Firebase.ProtoliteWellKnownTypes" Version="118.0.0.17" ExcludeAssets="All" /> After adding this i get runtime error: Field transportInfo_ for com.google.firebase.perf.v1.PerfMetric not found |
Solution 1 did not work for me, also got stuck at live error, but using @jeff-eats-pubsubs solution with using older version of firebase seems to have helped and the project is built successfully |
I also do not have a solution that works yet unless I use an older version....
Produces the following error:
|
Is there a fix for this issue ? |
@tranb3r not yet, follow xamarin/GooglePlayServicesComponents#898 |
…t/android-libraries#764 for more info. Added initial configuration types to support configuration system.
"Pause" migrating everything to a common template, and pivot to moving the remaining packages from the GPS repository to the AndroidX repository. This should enable us to eliminate the circular dependencies between the two repositories which should help fix the majority of the #764 issues going forward. Bring in the GPS and Glide templates as new "templateSet", and merge in all the build infrastructure pieces that the GPS repository had to make it build correctly.
Read this solution: |
TL:DR - Fixes
If you are seeing a Java compilation error of the form:
Solution 1
This may be fixable by simply updating your NuGet packages to the latest. This is the preferred solution.
Solution 2
This solution adds an explicit
<PackageReference>
to the needed transitive package version.Note: You will need to use versions that match the version of the primary package that is referenced.
If the problematic type starts with
androidx.lifecycle
, add this to yourcsproj
:If the problematic type starts with
kotlin.internal.jdk7
orkotlin.internal.jdk8
, add this to yourcsproj
:If the problematic type starts with
androidx.collection
, add this to yourcsproj
:How did we get here?
Let's take
androidx.lifecycle.DispatchQueue
as an example.The type has always existed in the Java package
androidx.lifecycle.lifecycle-runtime-ktx
. However, with the2.6.0
release, Android moved this type to theandroidx.lifecycle.lifecycle-common
Java package. This is fine if you reference matching versions of the NuGet packages:<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common" Version="2.6.1.3" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime.Ktx" Version="2.6.1.3" />
However, because these dependencies are referenced by other packages, and NuGet resolves transitive dependencies to the lowest version that satisfies the requirement, you can end up with mismatched references like:
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common" Version="2.6.1.3" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime.Ktx" Version="2.5.1.1" />
This is not fine, as both packages contain the
androidx.lifecycle.DispatchQueue
type, resulting in the type being duplicated:Specifically, in MAUI, this occurs because MAUI references
Xamarin.AndroidX.Navigation.Common
2.5.2.1
, which referencesXamarin.AndroidX.Lifecycle.Runtime.Ktx
2.5.1.1
:And the user adds a package like
Xamarin.AndroidX.Activity
1.7.2.1
which eventually referencesXamarin.AndroidX.Lifecycle.Common
2.6.1.3
:How does Java/Maven handle this?
Java/Maven avoids this issue by requiring an exact version match between
androidx.lifecycle.lifecycle-runtime-ktx
andandroidx.lifecycle.lifecycle-common
. That is, the POM file forandroidx.lifecycle.lifecycle-runtime-ktx
lists its dependency as:The square brackets (
[]
) denote an exact match, rather than a greater than or equal match.Our NuGet packages allow greater than or equal match, which allows the version to incorrectly differ from each other.
Long-term fix
In order to handle this long-term and help prevent this issue from recurring when other types move in the future, we need to duplicate Java/Maven's "exact match".
Unfortunately, publishing fixed packages will not make this error go away yet, because the fixed package needs to be referenced by MAUI. After fixed packages are published, MAUI will need to reference them and make a new release.
Thus, we will be living with the issue for a while.
Caveats
Using "exact match" versions will fix the
androidx.lifecycle
case (and potential future cases), but it will not fix thekotlin.internal
case, as the Kotlin POM does not specify an "exact match" for this case:Original Details
Certain
PackageReference
constellations can cause 2 errors:or
Basically, the problem is that maven package authors (Google, JetBrains) move types from version to version, from Maven artifact to another Maven artifact. So, in rare cases even trivial transitive dependencies cause such errors if nugets transitively reference nugets with bindings where the same type rasides, but under different version.
Team does publish "alingment bumps" to put transitive dependencies "in order", but probability for hitting these issues is still high on real world projects, especially with 3rd party libraries that depend on older AndroidX and GooglePlayServices-Firebase-MLKit (not regularly updated).
Workaround steps:
sometimes updating AndroidX 1st could help, but recommendation is to update all
PackageReferences
bin/
andobj
folders, restore and then buildIf you still encounter these issues open issue in AndroidX and/or GooglePlayServices-Firebase-MLKit repos and please add list of
PackageRererence
s.Related/Duplicates:
This issue is project specific (
PackagesReference
s dependent), so finding workaround is based on experience.Finding newer issues - search for;
Thus list of the similar issues:
AX (AndroidX)
#938
#935
#926
#918
#861
#805
#800
#797
#793
#788
#752
#749
#747
#742
#717
#634
#525
#509
#505
#756 (comment)
GPS-FB-MLKit (GooglePlayServices, Firebase, ML Kit)
xamarin/GooglePlayServicesComponents#909
xamarin/GooglePlayServicesComponents#898
xamarin/GooglePlayServicesComponents#897
xamarin/GooglePlayServicesComponents#889
xamarin/GooglePlayServicesComponents#852
xamarin/GooglePlayServicesComponents#825
xamarin/GooglePlayServicesComponents#475
xamarin/GooglePlayServicesComponents#379
MAUI
dotnet/maui#25261
dotnet/maui#20561
dotnet/maui#18665
dotnet/maui#18118
dotnet/maui#17935
dotnet/maui#16448
dotnet/maui#14954
dotnet/maui#11353 (comment)
More references
https://stackoverflow.com/questions/77487528/net-maui-push-notifications-with-firebase-cloud-mesaging
firebase/firebase-android-sdk#5997
firebase/firebase-android-sdk#5999
https://stackoverflow.com/questions/66344110/r8-says-type-is-defined-multiple-times-in-build-transforms-and-in-build-tmp-ko/
Steps to Reproduce
N/A
Did you find any workaround?
Workaround steps:
sometimes updating AndroidX 1st could help, but recommendation is to update all
PackageReferences
bin/
andobj
folders, restore and then buildRelevant log output
The text was updated successfully, but these errors were encountered: