dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.95k stars 1.7k forks source link

Maui.essentials 7.096 incompatible with Android GooglePlayServices Nugets like recaptcha #18118

Closed rfrailemartinez closed 9 months ago

rfrailemartinez commented 10 months ago

Description

if you have a net 7 project with

true

And add for example nuget Xamarin.Google.Android.Recaptcha, that has referente to Xamarin.GooglePlayServices.--- if you try to build app you get next error:

/Users/rfraile/proyectos/SELAE/Workspace/SELAE.Droid: Error JAVA0000: Error in obj/Debug/net7.0-android33.0/lp/135/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class:
Type androidx.activity.OnBackPressedDispatcherKt is defined multiple times: obj/Debug/net7.0-android33.0/lp/135/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class, obj/Debug/net7.0-android33.0/lp/103/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj/Debug/net7.0-android33.0/lp/135/jl/classes.jar
androidx/activity/OnBackPressedDispatcherKt.class
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:98)
    at com.android.tools.r8.D8.main(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj/Debug/net7.0-android33.0/lp/135/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class
    at Version.fakeStackEntry(Version_3.3.75.java:0)
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:75)
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:27)
    at com.android.tools.r8.internal.Fj.b(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:2)
    at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:22)
    at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:17)
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:85)
    ... 1 more
Caused by: com.android.tools.r8.internal.f: Type androidx.activity.OnBackPressedDispatcherKt is defined multiple times: obj/Debug/net7.0-android33.0/lp/135/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class, obj/Debug/net7.0-android33.0/lp/103/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class
    at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:14)
    at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:22)
    at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:33)
    at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:10)
    at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
    at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:6)
    at com.android.tools.r8.graph.B2$a.e(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
    at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:110)
    at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
    at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:25)
    at com.android.tools.r8.D8.d(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:606)
    at com.android.tools.r8.D8.c(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:1)
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:24)
    ... 5 more
El directorio "obj/Debug/net7.0-android33.0/lp/135" es de "androidx.activity.activity-ktx.aar". (JAVA0000) (SELAE.Droid) java

I think is important that you can specify the maui essentials versions that you want to use, like we did before net7 with Xamarin essentials nuget. is there a way to do that?

Thank you

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

7.0.96

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

AnnYang01 commented 10 months ago

Verified this on Visual Studio Enterprise 17.8.0 Preview 4.0 using below Project (.NET 7.0), error JAVA0000 will occur, but it does not repro on .NET 8.0 project. MauiApp1.zip .NET 7.0 image .NET 8.0 image

ghost commented 10 months ago

Hi @rfrailemartinez. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

rfrailemartinez commented 10 months ago

Hi @AnnYang01, it is a great notice that it is fixed in net8 preview. This could be a solution for the fisrt part of the problem.

But the main problem is that I work in a big company with a lot of projects, part of this project are updated and part of them not, for example if I publish an app today, maybe this client doesn´t ask for fix or change in 6 or 10 months, maybe this client only wants a change over their tablets version, besause the app is not in google play.

The new way to insert Essentials in projects makes you to be up to day with all the nugets that could be in conflict, including manual bindings that are made in specifiq android and androidx versions. I think we should have the option to put the version of essentials we waant to do, something like: <UseMauiEssentials version="7.0.96">true</UseMauiEssentials> when we used Xamarin.essentials nugets, you could select older version. Maybe there is a way but I don´t know how.

I think this problem is not only for Essentials, it is also a problem with true, where you open a project that you did one year ago that compiles and works, and a new Maui version relased during this time could break something.

thank you for your support

mattleibow commented 10 months ago

@moljac thoughts?

ghost commented 10 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

moljac commented 10 months ago

@moljac thoughts?

Type X is defined multiple times:

Known issue:

https://github.com/xamarin/AndroidX/issues/764

The problem is

  1. we cannot keep pace with google, so bindings are not 1:1
  2. nuget and maven SemVer rules (min, max, range, pinning/exact) differ we did some PRs to solve that, but not tested extensively yet
  3. google moving types around from artifact to artifact from version to version
  4. complexity of real-world projects (AX, GPS-FB-MLKit packages then plugins) and transitive dependencies Most issues are from real world apps and solution is to investigate dependency forest for PackageReferences. If the offending package is found adding explicit PackageReference with latest version does solve the problem in most cases.

In this case GPS-FB-MLKit repo was not updated for 3 moonths, because CI buids fail because of Cake.Tool. I fixed Cake.Tool but version 3.2.0 was not released yet. I do use locally preview and I did create PR so we could use it in AX and GPS-FB-MLKit repos.

https://github.com/xamarin/AndroidX/pull/802

So, in this case (quick-n-dirty analysis) I would explicitly add Xamarin.AndroidX.Activity.* 1.8.0.1 packages. If that does not help I must investigate dependencies.

2nd option would be to wait for updates and I hope I will be able to release soon.

moljac commented 10 months ago

1st round of updates was merged, tagged, but publishing fails, because required ComponentDetection (Components Governance step) step fails because aar files are not recognized.

Shortly after that there will be more updates

https://github.com/xamarin/GooglePlayServicesComponents/pull/803

moljac commented 10 months ago

From community feedback:

Try adding following references:

<PackageReference Include="Xamarin.AndroidX.Collection" Version="1.3.0.1" />
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.3.0.1" />

Related:

https://github.com/xamarin/AndroidX/issues/800#issuecomment-1774562211

moljac commented 9 months ago

@rfrailemartinez

Did you try this workaround??

Try adding following references:

<PackageReference Include="Xamarin.AndroidX.Collection" Version="1.3.0.1" />
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.3.0.1" />

.NET Android team released 2 rounds of GPS-FB-MLKit nugets. Can you please update your dependencies to latest and see? And please provide feedback here. Thanks.

ghost commented 9 months ago

Hi @rfrailemartinez. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

moljac commented 9 months ago

Closing this issue. If the proposed solution does not work - open new issue please

rfrailemartinez commented 9 months ago

Hi @moljac,

Excuse me for the delay, we remove essentials from our project. I have tested now and it's not necessary to add <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.3.0.1" /> <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.3.0.1" /> I think maybe verion 7.0.100 fix the problem that we had with 7.0.96

It is a pity, but we decide that we are not going to use essentials in any net project until we have something similar to nuget version selection. We have a lot of clients, some of them banks or similar, and we must have a way to specify the version of the libraries we use, like we said before, for example something like <UseMauiEssentials Version="7.0.96">true</UseMauiEssentials> We can not block a pass to production because for example a new verion of essentials appears one day before, the app doesn´t compile and we have to look for what package is in collision and have to be updated.

Thank you very much for your support and if version selection is develop, please advise us. We can test anything else more, that you think it can help you improve this. We love xamarin (Net mobile), and we have a lot of projects: Native, Forms, and starting projects with Maui and Net mobile.

dodikk commented 9 months ago

@AnnYang01 I have tried to build the project you've attached in a zip file on MacOS with "Visual Studio for mac" build 17.6.6 (build 408). And it fails both with net7 and net8 <TargetFrameworks> in the .csproj file. Any ideas?

AnnYang01 commented 9 months ago

Hi @dodikk, you can open a new ticket and provide more details of the failed error and attach a simple project.