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

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.

Related

UWP project added to Xamarin is not compatible with netstandard2.0

I have a Xamarin.Forms app (only doing things for Android now) where I added a project from an UWP app. With this, I get two erros which I cannot solve. I've found some things on the internet, but nothing for my specific situation.
The erros are:
Project UWP.Project is not compatible with netstandard2.0 (.NETStandard,Version=v2.0).
Project UWP.Project supports: uap10.0.17763 (UAP,Version=v10.0.17763).
Project UWP.Project is not compatible with monoandroid11.0 (MonoAndroid,Version=v11.0).
Project UWP.Project supports: uap10.0.17763 (UAP,Version=v10.0.17763).
How do I solve this?
I have a Xamarin.Forms app (only doing things for Android now) where I added a project from an UWP app.
It looks you need to update the UWP project target version to 17763. For adding the new platform for existing Forms app, you may refer to this document. And please note making the following changes to UWP MainPage.xaml
Inside the <Page> tag, add: xmlns:forms=“using:Xamarin.Forms.Platform.UWP

How to fix Xamarin Forms pipeline Target Framework error

Locally, I can build and run my Xamarin Forms application with no issues. In my Azure build pipelines I have my master branch failing because of my target framework version. It says it is 9.0 when it should be at least 10.0.
In my Android project file I have the framework version set to 10.0. I have made sure it is also v10 in the properties tab for the project. Yet I still get the below error.
##[error]C:\Users\VssAdministrator\.nuget\packages\xamarin.forms\5.0.0.2012\build\Xamarin.Forms.targets(188,5): Error XF005: The $(TargetFrameworkVersion) for MyApp.Android (v9.0) is less than the minimum required $(TargetFrameworkVersion) for Xamarin.Forms (10.0). You need to increase the $(TargetFrameworkVersion) for MyApp.Android.
Try to open your .csproj file,and manually modify its targetFrameworkVersion.
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
Verify that BOTH of the following project properties are set to 10.0:
Application / Compile using Android version (Target Framework).
Android Manifest / Target Android version.
https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/android-api-levels
If those are already both 10.0, then make sure the Azure build pipeline has up-to-date versions of Android SDKs and tools.
Another way to fix:
If you are able to create a new sample solution, and successfully build that via Azure, then start a new solution, and add all your files to it.

Is this ExportRenderer still required in Xamarin Forms 4.4 +

I have a couple of questions about the WKWebview in Xamarin Forms
1) From https://github.com/xamarin/Xamarin.Forms/pull/3346:
To opt-in to using WkWebView add the following to the AssemlyInfo.cs file of your iOS C# project file
[assembly: ExportRenderer(typeof(WebView), typeof(Xamarin.Forms.Platform.iOS.WkWebViewRenderer))]
Is this assembly still necessary to use in Xamarin Forms 4.4? Apparently WKWebView is the default view in XF4.4 so it's unnecessary?
2) Are there any visual changes between the UIWebView and the WKWebview? I updated my app from XF3.4 to 4.4 because I heard of the WebView change, but there doesn't seem to be any visual difference, but there is one weird bug in 4.4 where the loading icon won't disappear from the middle of my screen even though my page appears to have loaded properly...
Thanks!
From the latest document of webView, WKWebView has replaced UIWebView since Xamarin.forms 4.5:
Starting in April 2020, Apple will reject apps that still use the
deprecated UIWebView API. While Xamarin.Forms has switched to
WKWebView as the default, there is still a reference to the older SDK
in the Xamarin.Forms binaries. Current iOS linker behavior does not
remove this, and as a result the deprecated UIWebView API will still
appear to be referenced from your app when you submit to the App
Store.
A preview version of the linker is available to fix this issue. To
enable the preview, you will need to supply an additional argument
--optimize=experimental-xforms-product-type to the linker.
The prerequisites for this to work are:
Xamarin.Forms 4.5 or higher – Pre-release versions of Xamarin.Forms
4.5 can be used.
Xamarin.iOS 13.10.0.17 or higher – Check your Xamarin.iOS version in
Visual Studio. This version of Xamarin.iOS is included with Visual
Studio for Mac 8.4.1 and Visual Studio 16.4.3.
Remove references to UIWebView – Your code should not have any
references to UIWebView or any classes that make use of UIWebView.
Have a look at this thread would help.
For your first question, I think it is no longer needed in Xamarin.forms 4.5+.
For your second question, if you have any question, you can open an issue in Github of Xamarin.forms.

cannot run prism xamarin with Xamarin.Forms 3.5.0.62956-pre2 or 4.0 pre2

been trying to play with the new stuff that will soon coming out from xamarin form
I create a new Prism xamarin app
I upgrade the nuget packages to point to xamarin 3.5 or 4.0
but I cannot get the solution to run.
It just hangs!!
It works when I do the same thing with a standard xamarin form template
I know its just preview but I would like to know if somebody has tried to compile and run any app using prism xamarin and the preview xam forms.
many thanks
As far as I am aware there should not be any issues with Prism when targeting Xamarin Forms 3.5+.
That said if you're wanting to target one of the pre-releases I would suggest either installing the current preview on NuGet which targets 4.0-pre1, or the latest CI build which targets 3.5-pre2 and has a number of great new features including a more robust API for IContainerRegistry as well as support for Tuples in INavigationService.

Xamarin Forms how to check it contains the latest Api for Android and iOS

Hi newbie on Xamarin Forms.
I am a bit of confuse on using Xamarin forms.
With the following questions, I hope you can help me to understand to use it for development.
Currently I am using VS2015 Community version
1) If I have done the Settings on Cross Platform development to include C#/.Net(Xamarin v4...), do I still need to download the Xamarin at Xamarin.com?
2) Understand Android and iOS have different Api level (Sdk ver) and iOS ver8,9,10 respectively.
So, When google releases new api or Apple releases new iOS ver, How do I update Xamarin to use them? what I need to and How I handle Android and iOS new update respectively? What are the steps to take?
3) If I have Updated Xamarin, is this means it has included all the latest Api for Android and iOS
4) Can I use Xamarin for VS2017 as compare to VS2015 is more matured?
Thanks
You can and should use latest and greatest tools available, unless you have some limitations. Use Visual Studio 2017, it provides an easy installation of Xamarin.
When a new version of platform SDK is released by Google or Apple for example, you will have to:
Download & install new platform SDK for Android / iOS
Update Xamarin.Forms nuget package in the project
Additionally in case of iOS you may need to update Xcode
Xamarin.Forms documentation can answer all of your questions, so I suggest to get familiar with it.
I think you'll need to add some steps.
First - try create Xamarin Forms project and buil it(for Android). If you have errors - please read this manual
You need to check the update in several places.
2.1. About the new version Xamarin you will be informed Visual Studio.
For VS 2015 Check next setting - Service - Parametrs - Update Xamarin(checked).
For VS 2017 - You'll see the checkbox on the top right.
2.2 About update Android Api -You must learn manually. Check in VS
Service - Android - Package manager SDK Android. The new AIPI is a great event in the world of android - but you need to sit behind the news.
2.3 Also packages(Xamarin Forms and other) are updated - you need check nuget packages for your solution.
2.4. You must manual run update Xamarin for your mac. This is an extensive topic. Please read this article.
No is it. You need some manual actions(see item 2).
VS 2017 Has new features and new bugs ). I use VS 2017.

Resources