I have converted a Xamarin Android App to a net6.0-android app. It compiles fine but when it starts linking, it acts like it is trying to link Android libraries instead of AndroidX libraries. The following is a snippet of the type of linking errors I am getting.
4>obj\Debug\net6.0-android33.0\android\src\mono\android\support\v4\view\ViewPager_OnAdapterChangeListenerImplementor.java:33: error: package android.support.v4.view does not exist
4> private native void n_onAdapterChanged (android.support.v4.view.ViewPager p0, android.support.v4.view.PagerAdapter p1, android.support.v4.view.PagerAdapter p2);
4> ^
4>obj\Debug\net6.0-android33.0\android\src\mono\android\support\v4\view\ViewPager_OnAdapterChangeListenerImplementor.java:33: error: package android.support.v4.view does not exist
4> private native void n_onAdapterChanged (android.support.v4.view.ViewPager p0, android.support.v4.view.PagerAdapter p1, android.support.v4.view.PagerAdapter p2);
4> ^
4>obj\Debug\net6.0-android33.0\android\src\mono\android\support\v4\view\ViewPager_OnPageChangeListenerImplementor.java:8: error: package android.support.v4.view.ViewPager does not exist
4> android.support.v4.view.ViewPager.OnPageChangeListener
4> ^
4>obj\Debug\net6.0-android33.0\android\src\mono\android\support\v4\view\ViewPropertyAnimatorListenerImplementor.java:8: error: package android.support.v4.view does not exist
4> android.support.v4.view.ViewPropertyAnimatorListener
4> ^
4>obj\Debug\net6.0-android33.0\android\src\mono\android\support\v4\view\ViewPropertyAnimatorUpdateListenerImplementor.java:8: error: package android.support.v4.view does not exist
4> android.support.v4.view.ViewPropertyAnimatorUpdateListener
4>
4>obj\Debug\net6.0-android33.0\android\src\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.java(23,7): javac.exe error JAVAC0000: error: cannot find symbol
4>obj\Debug\net6.0-android33.0\android\src\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.java(23,7): javac.exe error JAVAC0000: if (getClass () == CustomTabsClient_CustomTabsCallbackImpl.class)
4>obj\Debug\net6.0-android33.0\android\src\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.java(23,7): javac.exe error JAVAC0000: symbol: method getClass()
4>obj\Debug\net6.0-android33.0\android\src\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.java(23,7): javac.exe error JAVAC0000: location: class CustomTabsClient_CustomTabsCallbackImpl
4>obj\Debug\net6.0-android33.0\android\src\android\support\customtabs\CustomTabsClient_CustomTabsCallbackImpl.java(23,7): javac.exe error JAVAC0000:
4>obj\Debug\net6.0-android33.0\android\src\crc64a98abb514ffad9f1\CustomTabsServiceConnectionImpl.java(23,7): javac.exe error JAVAC0000: error: cannot find symbol
4>obj\Debug\net6.0-android33.0\android\src\crc64a98abb514ffad9f1\CustomTabsServiceConnectionImpl.java(23,7): javac.exe error JAVAC0000: if (getClass () == CustomTabsServiceConnectionImpl.class)
4>obj\Debug\net6.0-android33.0\android\src\crc64a98abb514ffad9f1\CustomTabsServiceConnectionImpl.java(23,7): javac.exe error JAVAC0000: symbol: method getClass()
4>obj\Debug\net6.0-android33.0\android\src\crc64a98abb514ffad9f1\CustomTabsServiceConnectionImpl.java(23,7): javac.exe error JAVAC0000: location: class CustomTabsServiceConnectionImpl
4>obj\Debug\net6.0-android33.0\android\src\crc64a98abb514ffad9f1\CustomTabsServiceConnectionImpl.java(23,7): javac.exe error JAVAC0000:
Does anyone have any ideas of what I can do to fix this?
Thanks,
Jim
Update!
These are the packages I am using. If anyone sees a glaring red flag that they don't support AndroidX, please let me know.
<PackageReference Include="IdentityModel.OidcClient" Version="5.2.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.1" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.1" />
<PackageReference Include="Microsoft.AppCenter.Distribute" Version="5.0.1" />
<PackageReference Include="MvvmCross" Version="9.0.2" />
<PackageReference Include="SByteDev.Serilog.Sinks.AppCenter" Version="1.0.2" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Xamarin" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.4.0.3" />
I've been converting a number of Xamarin.Android test apps without too many problems to .Net7. I'm writing a how-to support article at the moment which I hope to publish in the next couple of days with test projects to share. One of the points I intend to mention is not to do what you are attempting to do and that is to attempt to convert an app that is not already an AndroidX migrated app.
I think it would be one hell of a stretch to expect an android app targeted at Android 9 or 10 to be successfully migrated to .Net6 or .Net7. It might be possible, but I'd really doubt it. I would suggest fully migrating to AndroidX targeting Android 13 or at least 12, before even considering migrating to .Net.
You have plenty of time to do it, so there is no need to rush it. You've only got to read the .Net6 documentation, which I presume you have done, to realise that it is not a super simple procedure. I haven't even attempted to use their migration tool as the remarks in the docs give me no confidence that it would be any better than the AndroidX migration tool, which was practically next to useless. Like with AndroidX the best and most efficient way is unfortunately the hard way.
After posting this, I re-read your question more carefully. Sounds like you may have already converted to AndroidX. If you have, then I would suspect that you are using some 3rd party library that is still using the old support libs.
To clarify - as compared to the previous answer. The docs I was referring to https://github.com/xamarin/xamarin-android/wiki/Migrating-Xamarin.Android-Applications-to-.NET-6.
It dawned on me that I was creating some of my own Nuget packages. It turns out that one of them targeted the old android libraries. It was actually an old version of MvvmCross which pulled them in Transitively. Once I updated my Nuget to use the new MvvmCross and used the new version of my package in my app, it started working fine. Thanks to all who helped point me in the right direction, especially those who pointed out that it was trying to reference android.support.v4.view.ViewPager.
Related
Trying to reference Windows.Devices.Geolocation to use the Geolocator class from a .NET 6 core WinUI desktop head. I suspect - I am not sure - maybe the NetStandard flavor of Uno.dll intending to load here and that is why FileNotFoundException ?
FileNotFoundException: Could not load file or assembly 'Uno, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
<PackageReference Include="Uno.WinUI" Version="4.2.6" />
Perhaps a little bit of WinDBG helps anything ? For me nothing.
What is more, it is not just a run time issue, even Visual Studio can't locate the assembly in source :
Procmon reveils, the assembly is found in the right nuget folder but the respective application process log not found:
I made a PR to your GitHub repro, but the steps needed were as follows.
First, the library had to be switched to multi-targeted by changing to <TargetFrameworks> in the .csproj:
<PropertyGroup>
<TargetFrameworks>net6.0;net6.0-windows10.0.19041.0</TargetFrameworks>
</PropertyGroup>
Now the net6.0 target is for all Uno targets and the net6.0-windows10.0.19041.0 is specifically for WinAppSDK on Windows desktop.
Secondly, the Uno.WinUI needs to be referenced only on Uno targets, so:
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0-windows10.0.19041.0'">
<PackageReference Include="Uno.WinUI" Version="4.2.6" />
</ItemGroup>
After these changes, the Windows project will no longer try to access the Geolocator type from Uno.dll and will use the proper Windows SDK Geolocator:
I am trying to run the Mobile project of ASP.NET Zero following their docs for Developing-Step-By-Step-Xamarin.
When I build the project, I get this error:
XA2002: Can not resolve reference: Abp.AutoMapper, referenced by Acme.PhoneBookDemo.Mobile.Shared. Please add a NuGet package or assembly reference for Abp.AutoMapper, or remove the reference to Acme.PhoneBookDemo.Mobile.Shared.
The package Abp.AutoMapper is installed in Acme.PhoneBookDemo.Mobile.Shared
and it is already referenced in the *.csproj:
<PackageReference Include="Abp.AutoMapper" Version="4.2.0" />
Can you please help me?
Solved , the package wasn't installed in *.Droid project but installed in *.Ios and *.Mobile.Shared projects.
Installing it in the *.Droid project resolve the issue.
Please tell me how to fix the problem. I updated Xamarin forms dll.
I get the following error:
Error error: cannot find symbol
private native void n_onInflate (android.support.v7.widget.ViewStubCompat p0, android.view.View p1);
symbol: class ViewStubCompat
location: package android.support.v7.widget
obj\Debug\android\src\mono\android\support\v7\widget\ViewStubCompat_OnInflateListenerImplementor.java
Error error: cannot find symbol
public void onInflate (android.support.v7.widget.ViewStubCompat p0, android.view.View p1)
symbol: class ViewStubCompat
location: package android.support.v7.widget
obj\Debug\android\src\mono\android\support\v7\widget\ViewStubCompat_OnInflateListenerImplementor.java
Error error: package android.support.v7.widget.ContentFrameLayout does not exist
android.support.v7.widget.ContentFrameLayout.OnAttachListener
obj\Debug\android\src\mono\android\support\v7\widget\ContentFrameLayout_OnAttachListenerImplementor.java
Error error: package android.support.v7.widget.FitWindowsViewGroup does not exist
android.support.v7.widget.FitWindowsViewGroup.OnFitSystemWindowsListener
\obj\Debug\android\src\mono\android\support\v7\widget\FitWindowsViewGroup_OnFitSystemWindowsListenerImplementor.java
Error error: package android.support.v7.widget.ViewStubCompat does not exist
android.support.v7.widget.ViewStubCompat.OnInflateListener
\obj\Debug\android\src\mono\android\support\v7\widget\ViewStubCompat_OnInflateListenerImplementor.java
Did you "update all Nuget packages"? This will download the incorrect versions of the Google libs. You will have to update the Forms packages manually, they will then pull in the required dependencies.
Also make sure you update the packages in all of your projects (the actual Forms project and the platform specific ones).
Finally, clean the solution and rebuild.
James Montemagno explains the issue perfectly here:
Xamarin Forums
I suspect you have updated all packages which will require manual intervention as described by #Krumelur above.
I have a Xamarin iOS project where I have just added SQLCipher to my packages. I now get a build error saying:
iOS/MTOUCH: Error MT0034: Cannot reference 'monotouch.dll' in a
Xamarin.iOS project - it is implicitly referenced by
'SQLite.Net.Platform.SQLCipher.XamarinIOS, Version=4.1.1.0,
Culture=neutral, PublicKeyToken=null'. (MT0034) (myProject.iOS)
I'm not sure how to fix this, I have tried deleting the sqlcipher package and adding again, rebuilding, and restarting Xamarin but no luck. Thanks for any help
When I try to build the application I get an exception the following exception :
C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(681,3): error : Failed to resolve assembly: 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'
I tried cleaning the project and building it again, also updated the Xamarin.Forms packages but still with no luck.
A little overview on the stack trace :
2>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(681,3): error : Failed to resolve assembly: 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'
2> Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch execution finished. (TaskId:153)
2> MTouch: 2016-07-05T14:27:15.8191415+05:30 - Finished (TaskId:153)
2> Output Item(s): _NativeLibrary= (TaskId:153)
2>Done executing task "MTouch" -- FAILED. (TaskId:153)
Has anyone received this error? I am running the latest Xamarin for Visual Studio.
As mentioned in the comments above by #SushiHangover Java.Interop.dll is from Xamarin.Android and I was getting an error in Xamarin.IOS.
I had a reference of Mono.Android in PCL which is always referenced in Xamarin.IOS so indirectly I was referencing dll of Xamarin.Android to Xamarin.IOS. Removing the reference from PCL solved my problem.
Step-by-step instructions on how to fish this one out, as it took me some time to find where the 'Android polluted' peace of code was.
Unload your Common code project
Open .csproj look for something like this
<ItemGroup>
<Reference Include="Mono.Android">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\MonoAndroid\v11.0\Mono.Android.dll</HintPath>
</Reference>
Delete this segment from csproj.
Load the project
Clean and rebuild the solution having iOS as startup Project, at this point, you will get a build error that will show which .cs file fails to build due to missing reference.
Go there and move the mechanism to an Android specific project.
As mentioned by #AkashAmin 'Mono.Android' referenced should not be there in PCL project.
But with this, also make sure that you have not added any 'Android' specific code in PCL project by adding 'using Android', if this was done then you need to remove this code by using 'Dependency Services', Click here
I had the same problem and when I removed the android.mono reference from pcl project it worked fine.
I think it happens because we are building project in ios and it doesn't have any android libraries
Platform specific code within the Shared Project will cause iOS compiler to attempt to use the platform specific assemblies when compiling.
In my case, I had a reference within my Shared Project's code, within the "using" statements, which was causing iOS to attempt to link to Android specific assemblies.
Removing the code from the Shared Project allowed for successful compiling of the project.
Just in case, I got this error from working with ReSharper on VS2013 (https://bugzilla.xamarin.com/show_bug.cgi?id=41627).
What I did was use the Workaround to explicitly add java.interop.dll assembly to my project. This problem doesn't affect Build so you can deploy first and VS will download java.interop to your app's obj\Debug\linksrc folder, which you can reference...
You need to check your PLC project on Android link. In PLC project ctrl+f and lets go find "Android" and delete it.