Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Adding Xamarin.Forms breaks references #75

Closed
TimBo93 opened this issue Nov 8, 2017 · 14 comments
Closed

Adding Xamarin.Forms breaks references #75

TimBo93 opened this issue Nov 8, 2017 · 14 comments
Assignees

Comments

@TimBo93
Copy link

TimBo93 commented Nov 8, 2017

Xamarin.Android Version (eg: 6.0):

8.0 (Oreo)

Operating System & Version (eg: Mac OSX 10.11):

Windows 10 1709

Support Libraries Version (eg: 23.3.0):

Android 5.0 (API Level 21 - Lollipop)

Describe your Issue:

To implement SSO with IndentityServer i am trying to use ChromeCustomTabs as described here:
IdentityModel/IdentityModel.OidcClient.Samples

Now i want to add Xamarin.Forms support.

Steps to Reproduce (with link to sample solution if possible):

Install Xamarin.Forms Nuget with Version

<ItemGroup>
 <PackageReference Include="IdentityModel.OidcClient">
   <Version>2.3.0</Version>
 </PackageReference>
 <PackageReference Include="Xamarin.Android.Support.CustomTabs">
   <Version>26.1.0.1</Version>
 </PackageReference>
 <PackageReference Include="Xamarin.Forms">
   <Version>2.4.0.38779</Version>
 </PackageReference>
</ItemGroup>

Include any relevant Exception Stack traces, build logs, adb logs:

1>------ Build started: Project: AndroidClient, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3277: Found conflicts between different versions of "Microsoft.CSharp" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.
1>C:\AndroidClientVS2017\AndroidClient\MainActivity.cs(48,33,48,56): warning CS0618: 'OidcClient.LoginAsync(DisplayMode, int, object)' is obsolete: 'This method will be removed in a future version. Please change your code to use LoginRequest'
1>  AndroidClient -> C:\AndroidClientVS2017\AndroidClient\bin\Debug\AndroidClient.dll
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1500,2): warning : Ignoring C:\Users\tborowski\.nuget\packages\system.runtime.compilerservices.unsafe\4.4.0\ref\netstandard2.0 as it is a Reference Assembly
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.OS.CancellationSignal+IOnCancelListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.OS.CancellationSignal+IOnCancelListenerImplementor, Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : References to the type 'Android.Support.V4.OS.CancellationSignal.IOnCancelListenerImplementor' will refer to 'Android.Support.V4.OS.CancellationSignal+IOnCancelListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.View.ActionProvider+ISubUiVisibilityListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.View.ActionProvider+ISubUiVisibilityListenerImplementor, Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : References to the type 'Android.Support.V4.View.ActionProvider.ISubUiVisibilityListenerImplementor' will refer to 'Android.Support.V4.View.ActionProvider+ISubUiVisibilityListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.View.ActionProvider+IVisibilityListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.View.ActionProvider+IVisibilityListenerImplementor, Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : References to the type 'Android.Support.V4.View.ActionProvider.IVisibilityListenerImplementor' will refer to 'Android.Support.V4.View.ActionProvider+IVisibilityListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.View.IOnApplyWindowInsetsListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.View.IOnApplyWindowInsetsListenerImplementor, Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : References to the type 'Android.Support.V4.View.IOnApplyWindowInsetsListenerImplementor' will refer to 'Android.Support.V4.View.IOnApplyWindowInsetsListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.View.IViewPropertyAnimatorListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.View.IViewPropertyAnimatorListenerImplementor, Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : References to the type 'Android.Support.V4.View.IViewPropertyAnimatorListenerImplementor' will refer to 'Android.Support.V4.View.IViewPropertyAnimatorListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.View.IViewPropertyAnimatorUpdateListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.View.IViewPropertyAnimatorUpdateListenerImplementor, Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : References to the type 'Android.Support.V4.View.IViewPropertyAnimatorUpdateListenerImplementor' will refer to 'Android.Support.V4.View.IViewPropertyAnimatorUpdateListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : Duplicate managed type found! Mappings between managed types and Java types must be unique. First Type: 'Android.Support.V4.View.MenuItemCompat+IOnActionExpandListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; Second Type: 'Android.Support.V4.View.MenuItemCompat+IOnActionExpandListenerImplementor, Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1794,3): warning : References to the type 'Android.Support.V4.View.MenuItemCompat.IOnActionExpandListenerImplementor' will refer to 'Android.Support.V4.View.MenuItemCompat+IOnActionExpandListenerImplementor, Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompat;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompat$1;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompat$OnRequestPermissionsResultCallback;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityCompat$SharedElementCallback21Impl;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityManagerCompat;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/ActivityOptionsCompat;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/AppOpsManagerCompat;
1>  Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/BundleCompat;
1>  
1>  UNEXPECTED TOP-LEVEL EXCEPTION:
1>  java.lang.RuntimeException: Translation has been interrupted
1>  	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:615)
1>  	at com.android.dx.command.dexer.Main.runMonoDex(Main.java:313)
1>  	at com.android.dx.command.dexer.Main.runDx(Main.java:291)
1>  	at com.android.dx.command.dexer.Main.main(Main.java:247)
1>  	at com.android.dx.command.Main.main(Main.java:94)
1>  Caused by: java.lang.InterruptedException: Too many errors
1>  	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:607)
1>  	... 4 more
1>C:\Program Files (x86)\Microsoft Visual Studio\Preview\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2096,3): error : java.lang.IllegalArgumentException: already added :  Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat;
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

I remove /bin /obj restored nuget and restarted vs.
It seems to be that some references are broken with the current (stable) Xamarin.Forms Package.

Kind Regard
Tim

@TimBo93 TimBo93 changed the title Xamarin.Forms Adding Xamarin.Forms breaks references Nov 8, 2017
@Redth
Copy link
Member

Redth commented Dec 11, 2017

You hit a bit of an edge case here.

Take a look at your obj/project.assets.json file to see exactly what nuget resolved to use in terms of versions of implicit dependencies...

Basically, Xamarin.Forms 2.4.0.x wants v23.3.0 of Android Support libraries. Adding the CustomTabs v26.1.0.1 reference brings in Support.Compat 26.1.0.1 which brings in Annotations 26.1.0.1. Now, since none of the dependencies in the path of CustomTabs 26.1.0.1 depend on Support.v4 directly, there's really nothing linking it together with any of the shared dependencies of Xamarin.Forms, so this configuration is sort of technically ok, even though it obviously causes issues. What ends up happening is support.v4 v23.3.0 and support.compat 26.1.0.1 both contain some of the same classes (support v4 was split up in later versions and is really just a type forwarding library with no actual java classes embedded). This is why you're seeing the error.

Now to fix it, you basically need to add some more explicit <PackageReference declarations.

For instance, try adding:

    <PackageReference Include="Xamarin.Android.Support.Design">
      <Version>26.1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.v4">
      <Version>26.1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat">
      <Version>26.1.0.1</Version>
    </PackageReference>

@Redth Redth self-assigned this Dec 11, 2017
@Redth Redth closed this as completed Dec 11, 2017
@danielmeza
Copy link

Hi I @Redth I have the same issue, I added the explicit version, but still have the issue. I´m also using the IdentityModel.OidcClient.

I´m using windows and visual studio 2017.15.5

@Redth
Copy link
Member

Redth commented Dec 15, 2017

@danielmeza can you add a gist of your obj/project.assets.json file? I suspect it's resolving some mismatched Xamarin.Android.Support.* package versions...

@Redth Redth reopened this Dec 15, 2017
@danielmeza
Copy link

danielmeza commented Dec 15, 2017

@Redth my apologies, it build ok but I get this warning
warning : Ignoring C:\Users\...\.nuget\packages\system.runtime.compilerservices.unsafe\4.4.0\ref\netstandard2.0 as it is a Reference Assembly

and when I try to debug I get the followin error:
12-15 13:57:39.699 F/monodroid-assembly(27062): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration. 12-15 13:57:39.699 F/monodroid-assembly(27062): This might be due to an invalid debug installation. 12-15 13:57:39.699 F/monodroid-assembly(27062): A common cause is to 'adb install' the app directly instead of doing from the IDE.

I followed the instructions here:

But nothing work for me.

The project file
Litigio.Mobile.Android.zip

The project.assets.json file
project.assets.zip

build and debug output.zip

And it is related wiht this issue to.
https://forums.xamarin.com/discussion/100273/deploying-to-android-emulator-error-could-not-load-assembly-system-runtime-compilerservices-unsafe

@danielmeza
Copy link

danielmeza commented Dec 19, 2017

I temporaly solve the issue of the runtime exception, only change the Linker option in the android project from none to Sdk and User Assemblies and in iOS projec to fron none to Link Framework SDKs Only option.

@listepo
Copy link

listepo commented Dec 19, 2017

I have the same problem with latest xamarin forms(.net standard) and realm only for xamarin android

@toumir
Copy link

toumir commented Dec 21, 2017

exactly the same as @listepo

@ConX-Ryan
Copy link

ConX-Ryan commented Jan 15, 2018

I have the same issue. Except I'm using EntityFrameworkCore.SQlite
Is there any traction on a fix here? None of the workarounds seem to work for me

@danielmeza
Copy link

@ConX-Ryan did you try to change the Linker options?

@gesch80550
Copy link

@danielmeza - I tried the Linker option and found that my Bindings stopped working (on Droid and iOS). Anyone have other solutions for this system.runtime.compilerservices.unsafe issue?

@danielmeza
Copy link

@gesch80550

I tried the Linker option and found that my Bindings stopped working (on Droid and iOS). Anyone have other solutions for this system.runtime.compilerservices.unsafe issue?

It is normal to see that after change the Linker options and it is beacuse the linker are removing code that it is necesary to run your application, to solve the issue of broken binding you can add [Preserve(AllMembers = true)] on all class on your code or you can exlcude the entire proyect.
image
Note the Litigo.Mobile.Forms word in the Skip linkin assembly, that must solve your binding issue, in iOS is not necesary to put the linker option to full, you can only link the SDK Assemblies
image

@Redth
Copy link
Member

Redth commented Jan 29, 2018

This issue is actually one of https://github.com/xamarin/xamarin-android

There are a number of issues which are referring to this same problem:
dotnet/android#1162
dotnet/android#1196
dotnet/android#1154

Basically, the only current work around for this is to switch your projects to use packages.config instead of <PackageReference until a proper fix is released.

@Redth Redth closed this as completed Jan 29, 2018
@danielmeza
Copy link

Change to packages.config not solve the problem... it must remain open.

@danielmeza
Copy link

The issue is traking here dotnet/android#1196

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants