Xamarin.Android Build Error for Xamarin Forms 4 Solution - xamarin.forms

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.

Related

Xamarin.Forms upgraded to Maui - Visual Studio Cannot debug/run?

Application upgraded using Microsoft's auto upgrade command line tool.
Some code fixes, and the code builds successfully.
Visual Studio however does not show me any way to debug my app.
When trying to click on Debug anyway, a random Android Emulator from my list(which is not showing currently)
Will open, but deployment will fail without specifying the reason.
Has anyone managed to upgrade an existing Xamarin.Forms project to Maui?
I managed to make VS recognize the Android project in my converted solution.
I added the <SingleProject>true</SingleProject> property into my Android project's .csproj file under the first/main property group, closed VS, deleted Bin, Obj, .vs folders.
After starting VS again , I rebuilt and VS allowed me to debug on selected .net targets like a single project Maui solution.
This is very strange that it works, since this solution is made of 3 project like in a Xamarin.Forms solution, so it doesn't make since that adding this property solves the issue, but there you go.
Delete .bin and .obj folders. Delete solution's hidden .vs folder. Build. Does it show debug option now?
Try restarting VS (after the successful build). Now work?
If not, Create a new project using Maui template.
Use solution / manage all nugets to add nugets used by your project.
Copy all your source files into that new project.
Project / "Add existing items": all those source files.

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 android: Could not determine API level for $(TargetFrameworkVersion) of 'v8.1'

Getting following error when rebuilding xamarin forms android project.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2,2): Error XA0000: Could not determine API level for $(TargetFrameworkVersion) of 'v8.1'. (XA0000) (Myproject.Android)
Found the same issue in some other threads. The solution on there is open .csproj file and change AndroidUseLatestPlatformSdk from True to False, and rebuild. I found this solution on here and here.
But I don't know which .csproj file need to modify? Can some one tell it more clearly?
You'll want to edit Myproject.Android.csproj.
Here's how to edit a csproj in Visual Studio:
Visual Studio for Mac
Visual Studio on PC
1. Unload the Project
2. Edit the File
3. Reload the Project
Just go to options and then general
then select appropriate target version

error XF003: Xamarin.Forms require msbuild. xbuild is no longer supported

I am trying to build an iOS app on Mac, using the latest visual studio emulating as iPhone.
an attempt at debugging results in the error:
../packages/Xamarin.Forms.3.0.0.550146/build/netstandard1.0/Xamarin.Forms.targets: Error XF003: Xamarin.Forms require msbuild. xbuild is no longer supported. (XF003) (Work.App)
I have tried removing the build cache/bin and obj files to no avail, I can't find any resolution to this online.
Any tips?

XamarinForms CustomRenderer with .net standard 2.0 and prism7

I am trying out Prism7 together with AutoFac in a xamarinforms project.
I am trying to create a custom renderer for an entry control, nothing fancy here.
But for some reason i cannot get a reference to xamarin.forms and xamarin.forms.platform.ios/android namespaces in my ios and android project.
The project is based on the prism7 templates and the pcl is a .net 2.0
Normally I would expect
[assembly: ExportRenderer(typeof(Entry), typeof(BorderlessEntryRenderer))]
to work and connect my renderers but as said cannot reference xamarin.forms.
Anyone got an ideer?
I made it work.
Solution was to open project in Visual Studio Mac (I was in pc version before).
Then there is no problem seeing the namespaces. Rebuild and run both projects to see them work.
Go back to visual studio pc version and continue work there. If you have Resharper you need to clear cache otherwise it will look like you still have errors.
Must be a Visual Studio Pc or Resharper bug. Maybe I should use Mac version from now on :-)
I had the same problem. That's how I fixed it:
Add the correct references (ex: using myproject.myrenderers;)
Close the solution and Visual Studio (Windows).
Delete all bin and obj folders in the solution (including each platform).
Open VS and the project.
Clean.
Rebuild.
Done.

Resources