migrating from Xamarin 4 to Xamarin 5 - xamarin.forms

I just update all my nugget packages to Xamarinforms 5.0.0.2012, Xamarin Maps 5.0.0.2012, Xamarin.Forms.Visual.Material 5.0.0.2012, Xamarin Essentials 1.61 and prism 8.0.0.1909,.. all my packages and even my VS to the lastet version 16.9.3
Now when I run (f5) my android project on my samsung note 9,by usb, in the splash screen I got this error:
Java.Lang.RuntimeException Mensaje = Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.XXX.yyyyyy-xjKonazvnj9Dk6-OE4QIZQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.XXX.yyyyyy-xjKonazvnj9Dk6-OE4QIZQ==/lib/arm64, /data/app/com.XXX.yyyyyy-xjKonazvnj9Dk6-OE4QIZQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
and then the app hungs and got closed
thanks

When you upgrade your project from Xamarin.Forms 4.0 to 5.0 you have to migrate your Android project to AndroidX as well, which means that all Android.Support libraries changed to AndroidX libraries.
The crash error you posted shows that your project still have references to old Android.Support namespaces.
Microsoft provides some articles about how to migrate your app.
It's pretty straghtfoward and most of the process is done automatically for you:
AndroidX migration in Xamarin.Forms
How do I migrate my app to Xamarin.Forms 5.0?

Well thaks for the guide,...
The solution was easy
Open the AndroidManifest.xml
Search for android.support.v4.content.FileProvider
Replace in every place for androidx.core.content.FileProvider
Save and rebuild, that's all
Hope this help to someone

Related

Error com.opennetcf.extensions.pcl is not compatible with netstandard1.5

I'm trying to understand the root of this error:
Package com.opennetcf.extensions.pcl is not compatible with netstandard1.5
I get it when I try to update xamarin essentials from nuget in my xamarin forms project. If I don't update that package, the project works fine. This is what I don't understand. If the PCL is not compatilble with .net standard 1.5, why does the project currently work when I'm using both. Why do I only see this error when I try to update xamarin essentials?
I've been reading a lot of articles on PCL support but I'm not sure what I need to do in this case. My main concern is updating xamarin essentials.
Any thoughts?

Xamarin Android app out of the box shows undefined Android.Support, Android.Views, Android.Content in MainActivity

I needed to rebuild my fairly ancient Xamarin Forms app from scratch and in the process arrived at a situation where I had a new working iOS app but had needed to delete the draft Android app and start it again. So as a next step I added a vanilla Android app project out of the box and immediately what I saw was that (in MainActivity) Android.Support, Android.Views and Android.Content were undefined with wiggy red lines beneath -- for example in a reference to Android.Support.V7.Widget.Toolbar.
Trying to solve the problem, I set each of Target Framework, Minimum Android Version and Target Android Version to Android 9.0 Pie (API Level 28). In SDK Manager I checked that Android SDK Location and Java SDK Location were 'Found' and that Android SDK Platform 28 was installed.
The following NuGets came installed along with the project, I deleted them and reinstalled them (removing bin/obj folders in between): Xamarin.Android.Support.Core.Utils, Xamarin.Android.Support.CustomTabs and Xamarin.Android.Support.Design.
I tried installing NuGets Xamarin.Android.Support.v7.*. And I added the Xamarin.Forms NuGet. I tried adding 'use' declarations.
None of this helped.
For comparison I separately installed a blank Android app solution-- it worked perfectly out of the box.
Android is pretty new to me - would be grateful for suggestions on fixing this.
The app has a .NET Standard 2.0 project, an iOS project, the (vanilla) Android project (all three with Xamarin Forms), and a .NET Standard 2.0 library project.
I'm using Visual Studio for Mac V8.5.4 (stable) on MacOS 10.15.3.
I noticed that the content of MainActivity.cs is quite different, depending whether the Android project is created separately or as part of a Xamarin Forms solution. Also the provided NuGets are different. So perhaps what I was trying to do, adding an Android app to an existing XF solution, is simply not allowed.
To fix the problem, I created an empty Xamarin Forms solution with Android and iOS projects, added a further empty library project, then in Finder replaced the content of all the project folders, except the Android one, with the content of the corresponding folders in my working solution (the one with a working iOS app).
Migrating to AndroidX is a good idea though.
I don't know if this will help, but you should migrate to AndroidX as soon as possible, nevertheless. Xamarin has migrated to them, starting from Forms 4.5
Here is some more information about the libraries - Introducing AndroidX for Xamarin
There is a special NuGet package for the migration - Xamarin.AndroidX.Migration. Also available is a built-in functionality in Visual Studio - here
What I can suggest is you try to migrate to AndroidX libraries, since the old support libraries won't be supported from now on, and you will surely encounter some issues if not like this one, then something else will pop-up in the future.

Xamarin Forms Google AdMob errors when linking Sdk and User Assembly

I have successfully added Google AdMob to my Xamarin Forms app. App is working fine on emulator as well as device.
Now I am trying to reduce apk size by turning on Linker with "Sdk and User Assembly" option, in Android project.
As soon as I turn on linker I get following error -
Java.Lang.RuntimeException Message=Unable to get provider
com.google.android.gms.ads.MobileAdsInitProvider:
java.lang.ClassNotFoundException: Didn't find class
"com.google.android.gms.ads.MobileAdsInitProvider" on path:
DexPathList[[zip file
"/data/app/com.companyname.testapp-ja8UI5lHn0Hrtg1FqPOk8A==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.testapp-ja8UI5lHn0Hrtg1FqPOk8A==/lib/x86,
/data/app/com.companyname.testapp-ja8UI5lHn0Hrtg1FqPOk8A==/base.apk!/lib/x86,
/system/lib]]
Any suggestion on how do I fix this error and still reduce apk size?
Update
All the NuGet packages are up-to-date with latest version.
For Android -
For .NET Standard 2.0 -

Xamarin.Android Build Error for Xamarin Forms 4 Solution

I am trying to compile a newly created Xamarin.Forms solution using Visual Studio Pro 2019 version 16.1.3. I use the stable Xamarin.Forms version 4.0.0.425677. The solution contains an iOS, Android and UWP project.
When I try to compile I get the following Android compilation error even without having made any code changes.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(3326,2): error : A part of the path "AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.class" could not be found
The only related post I found was here which recommends to delete bin and obj folders in the Android project. This does not apply since I start with an new solution in the first place. Any ideas what the cause could be?
Well, it turns out that I only get this issue when I have the term "Xamarin" in my Android project name. This seems to confuse the Android compiler.

Java.Lang.RuntimeException: Unable to instantiate activity ComponentInfo while adding SplashActivity

I'm stuck on an issue while adding Splash screen using Xamarin Forms. I have implemented the splash screen with help of this link.
After that the app crashed. and show the given error popup.
Please help me
Thank you
You could refer to Jon Douglas's answer : Xamarin.Android app only finding launcher activity on clean compile
.
This issue has been fixed and be included in Visual Studio 15.5.5 or Visual Studio 15.6 Preview 3.
The respective Xamarin.Android version this fix is included in are Xamarin.Android 8.1.5.0 (Stable) and Xamarin.Android 8.2.0.6 (Preview)
Solution 1:
Update your Visual Studio to the latest version, Visual Studio 15.5.6 is available now.
Solution 2:
Delete your solution bin&obj folder
Rebuild again

Resources