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" />
CodePudding user response:
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.
CodePudding user response:
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.