Xamarin create application for android 4 (VS2017 15.5.5) - xamarin

im trying to create an android application with xamarin (VS 2017 15.5.5). The default settings (xamarin cross-platform - blank app / .net standard, targeting android 7) generates project that can be deployed via live player, but the build process generates error
Error The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'XamTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'XamTest.dll'
....
....
My goal is to create android application for android 4 (4.0.3 / 4.1) and higher, but changing the settings (target framework + min. version + target android ver. all set to 4.1) in project properties results in 15 errors of these kind:
Error: NU1202 Package Xamarin.Android.Support.v7.MediaRouter 25.4.0.2 is not compatible with monoandroid41 (MonoAndroid,Version=v4.1). Package Xamarin.Android.Support.v7.MediaRouter 25.4.0.2 supports: monoandroid70 (MonoAndroid,Version=v7.0)
Error: No resource found that matches the given name: attr 'colorAccent'. XamTest.Android C:\Dev\XamTest\XamTest\XamTest.Android\Resources\values\styles.xml
So i deleted all support libraries in NuGet package manager, some undefined styles and two pre-generated xaml files (Toolbar, Taskbar). Now i have 38 errors of this type
\Dev\XamTest\XamTest\XamTest.Android\obj\Debug\resourcecache\96A6E7245B001AFA9465D8F3C01B0DCD\res\layout\notification_template_big_media.xml:42: error: No resource identifier found for attribute 'layoutDirection' in package 'android' XamTest.Android C:\Dev\XamTest\XamTest\XamTest.Android\C
and one error
Error NU1202 Package Xamarin.Android.Support.Design 23.3.0 is not compatible with monoandroid41 (MonoAndroid,Version=v4.1). Package Xamarin.Android.Support.Design 23.3.0 supports: monoandroid43 (MonoAndroid,Version=v4.3)
No support library is linked (only xamarin.forms) so i dont understand where Suppurt.Design comes from...
I have spent two days with sdudying, reading doc, tutorials etc. but i havent found any suitable answer. So, is there any simple way how to set up an Android project targeting Android 4.1?
Thank you.

The latest version of Forms needs to compile against Android 8.0 (at least). In order to compile against API level 15, you would need to use a very old version of Forms.
Instead, compile against the latest API and set your min. and target APIs levels to 4.0.3
Under General setting, set the target framework:
Target framework: Use Latest installed platform (8.1)
Under Android Application:
Min Android version: Override - Android 4.0.3 (API level 15)
Target Android version: Override - Android 4.0.3 (API level 15)
This results in a manifest that includes:
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" />
Note: You will need to test against an Android 4.0.3 device/emualtor to ensure that you are not using APIs from later versions of the Android SDK.

Related

TargetFrameworkVersion problem of Xamarin.Form.Android

I am a beginner at Xamarin.Forms.
My project has to support Android 6 and I create a brand new project with Xamarin.Forms 4.8.0.1451, and then set the Compile using Android version to Android 6.
Now visual Studio reports this error:
Severity Code Description Project File Line Suppression State
Error The $(TargetFrameworkVersion) for Sample.Android (v6.0) is less than the minimum required $(TargetFrameworkVersion) for Xamarin.Forms (9.0). You need to increase the $(TargetFrameworkVersion) for Sample.Android. Sample.Android
It seems the current version Xamarin.Forms does not support Android 6, right?
How can I solve this? Whether I can only use a lower version Xamarin.Forms?
Thank you.
First the Target Framework (also known as compileSdkVersion) is the specific Android framework version (API level) that your app is compiled for at build time. This setting specifies what APIs your app expects to use when it runs, but it has no effect on which APIs are actually available to your app when it is installed. As a result, changing the Target Framework setting does not change runtime behavior.
The Target Framework identifies which library versions your application is linked against – this setting determines which APIs you can use in your app. For example, if you want to use the some method that was introduced in Android 6.0, you must set the Target Framework to API Level 23 or later.
We recommend that you always compile with the latest available Target Framework version.
So you don't need to set the Compile using Android version to Android 6,if you want it support Android 6,you just need set the Target Android Version or Minimum Android Version to android 6.
And you could see the Android version(MonoAndroid Version) that Xamarin.Forms depends on when you open the NugetPackage Manager.

Conditional Compilation in Xamrine.forms for iOS and Android

I had created Xamarin project. Which had Xamarin.Android and Xamarin.iOS projects.
Below are the steps i performed.
1) Added Define Symbols for ANDROID;IOS in compiler.
2) Added conditional coding in content page.
3) It is not able to find Specific coding for Android where there are libraries only addd in Android.
FM.LiveSwitch.Android 1.8.1.24030 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package FM.LiveSwitch.Android 1.8.1.24030 supports: monoandroid70 (MonoAndroid,Version=v7.0)
Is there any way i can add that in Xamrine.forms ?

Can't build Xamarin Forms, Android project, TargetFrameworkVersion v9.0 not is not supported

Trying to build a Xamarin Forms Android project. The Minimum Android Version and Target Android Version are set to "Android 8.1 (Api Level 27 - Oreo) in the project Properties.
Under the SDK Manager, I have API Level Versions (SDK Platforms) 21-28 installed.
When loading the project, I get the following error:
Severity Code Description Project File Line Suppression State
Error Project MyProjMobile.Android cannot build using TargetFrameworkVersion v9.0 because it s not supported. Please change your Xamarin.Android project to target an API version that is supported. 0
No matter what I set the TargetFramwork settings to (I tried lowering them), I continue to get the same error.
I have even tried loading this project after deleting the bin, obj and packages folders with no luck.
You can look at my manifest here:
https://www.dropbox.com/s/7dnp6qqknbbn5ee/AndroidManifest.xml?dl=0
Any ideas?

Xamarin - How to update Mono.Android version to resolve dependencies?

I'm trying to install a nuget package (Xamarin.Firebase.Firestore) which requires a newer version of Xamarin.GooglePlayServices.Basement (60.1142.0, I have 42.1021.1), which in turn requires me to update the xamarin.android.support packages. When I try to update those, I get this error
"Package Xamarin.Android.Support.Design 27.0.2 is not compatible with monoandroid80 (MonoAndroid,Version=v8.0). Package Xamarin.Android.Support.Design 27.0.2 supports: monoandroid81 (MonoAndroid,Version=v8.1)"
I've tried changing my target android version to 8.1, I've also updated my SDK as well as the build tools. I'm running Visual Studio 15.6.1. As a last ditch effort, I tried deleting the Mono.Android V8.0 reference and then adding a new reference to V8.1, but whenever I do so, Visual studio just ends up adding the reference with the path pointing to V8.0, even though the reference I added was clearly pointing to V8.1.
Anyone has a clue how to resolve this issue?
tried changing my target android version to 8.1
You need to change the Target Framework that is used to compile your android application, not the Target Android version (but assumably you would set these two to the same, read the Understanding Android API Levels link below.
Visual Studio for Windows:
Visual Studio for Mac:
Target Framework – Specifies which framework to use in building your application. This API level is used at compile time by Xamarin.Android.
Minimum Android Version – Specifies the oldest Android version that you want your app to support. This API level is used at run time by Android.
Target Android Version – Specifies the version of Android that your app is intended to run on. This API level is used at run time by Android.
Understanding Android API Levels
Manifest Entries:
Visual Studio for Windows:
Visual Studio for Mac:

Debug/Emulator getting started with Android using Xamarin

Using VS2015/Windows 10, I created a Blank App (Portable) and set the startup project to Droid. I had only one emulator by default, so I created a Galaxy Nexus/API 23/Intel Atom x86 using the AVD with HAXM.
I can't get this blank project to run on either emulator. When I hit debug, it goes through the motions and starts the emulator but nothing happens. If I run any project beyond the first time after I created a project I get the following error:
System.MissingMethodException: Method
'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
http://imgur.com/a/hZNUQ
Frame not in module http://imgur.com/a/KtsRD
This is what I have installed: http://imgur.com/a/iL7Wt
I have installed all the latest updates, the SDK's etc. I would simply like to get started and emulate a HelloWorld app.
UPDATE: still have the issues, here is some more information to track issue.
Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586
Microsoft .NET Core Tools (Preview 2) 14.1.21111.0
Microsoft .NET Core Tools (Preview 2)
Xamarin 4.2.1.64 (872717c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Inspector Support 1.0.0.0 (1f3067d)
Adds support for inspecting Xamarin and WPF apps.
Xamarin.Android 7.0.2.37 (ce955cc)
Visual Studio extension to enable development for Xamarin.Android.
Xamarin.iOS 10.2.1.5 (44931ae)
Visual Studio extension to enable development for Xamarin.iOS.
Installed Android SDKS:
Android SDK Tools 25.2.3
Android SDK Platform-tools 25.0.1
Android SDK Build-tools 23.0.2, 23.0.1, 22.0.1, 21.1.2
, 19.1
Android 7.1.1 (API 25) - SDK Platform, Google API's Intel x86 ATOM
Android 7.0 (API 24) - SDK Platform, Google API's Intel x86 ATOM
Android 6.0 (API 23) - SDK Platform, Google API's Intel x86 ATOM
Android 5.1.1 (API 22) - SDK Platform, Google API's Intel x86 ATOM
Android 5.0.1 (API 21) - SDK Platform, Google API's Intel x86 ATOM
Android 4.4.1 (API 19) - SDK Platform, Google API's Intel x86 ATOM
http://imgur.com/a/vZZmf
Reproduction steps
1) Create a new Blank PCL project, targetted .NET Framework 4.5
2) Right off the bat I have the following 4 Warning messages
Warning IDE0006 Error encountered while loading the project. Some project features, such as full solution analysis for the failed project and projects that depend on it, have been disabled. App5.Droid 1 Active
Warning The "ResolveLibraryProjectImports" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load assembly 'App5, Version=, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'App5.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName, ReaderParameters parameters)
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(String fullName)
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.GetAssembly(String fileName)
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(ICollection1 jars, ICollection1 resolvedResourceDirectories, ICollection1 resolvedAssetDirectories, ICollection1 resolvedEnvironments)
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() App5.Droid
Warning Type universe cannot resolve assembly: System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. App5.UWP
Warning Cannot resolve Assembly or Windows Metadata file 'System.Runtime.dll' App5.UWP D:\Visual Studio 2015\Projects\App5\App5\App5.UWP\App5.UWP.csproj
http://imgur.com/a/EwIQY
3) Right click on the Droid project - properties
Compile using: Use Latest Platform (Android 7.0 Nougat)
Min Android: Android 4.0.3 (API level 15 - Ice Cream Sandwich)
Target Android version: Use compile SDK version
http://imgur.com/a/yZyAv
4) Set startup project as Droid, RUN using AVD_GalaxyNexus_ToolsForApacheCordova (Android 4.4 - API 19)
5) Pop-up message: Running an x86 based Android Virtual Device is 10x faster. We strongly recommend creating a new AVD. Clicked OK
6) Android Emulator Starts. VS15 message bar: 'Deploying AVD' for a long time....then 'Ready' orange bar. Few more minutes and new pop-up opens: 'Find Source: NavigationPageRenderer.cs' ...not sure where this file is/what this file is supposed to be.
http://imgur.com/a/DVYjJ
7) When I click cancel, I get the error message:
System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
http://imgur.com/a/KGvEG
Reproduced same issue on multiple machines
Update: So I just reproduced your issue and I am sorry that you and other ran into this. It looks like there was an issue in the templates and I am working with the team to quickly resolve this.
To fix:
Simply right click on the android project and select "Manage Nuget Packages"
Go to Updates
Find Xamarin.Android.Support.v7.AppCompat
Select version 23.3.0 from the version picker and hit Install
You additionally will need to install the RecyclerView 23.3.0 NuGet Package. Go to Browse and search for: Xamarin.Android.Support.v7.RecyclerView and make sure to pick 23.3.0 to install for the correct version
Now do a full clean/rebuild and it should work
This should install the correct versions of everything you need for Android
So, it looks like you are attempting to create a Blank Xamarin.Forms application, not a traditional Xamarin application.
My first recommendation is to try to just create a blank Android application with Xamarin. This will have very little dependencies and you can see if it starts to deploy out of the box.
Looking at your Installed Android SDKs, I would recommend Uninstalling anything Under Android 7.1.1 (API 25) as it is not supported yet and may be causing issues downloading NuGet packages.
Here is what mine looks like as of today:
Looking at your Warnings I think it will go away once you uninstall API 25, not sure why that is getting installed unless you maybe already installed Android Studio?
Also, if you are targting API 24+ you'll have to install the Java JDK 1.8. I would suggest removing 1.7 unless you need to use previous versions. The release notes for Xamarin.Android 7.0 have more information as well: https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.0/
Note: Xamarin.Android 7.0 requires JDK 1.8 to use the Android Nougat (API 24) APIs. You can continue to use earlier versions of the JDK if targeting earlier Android API levels:
JDK 1.8 - up to API 24+ JDK 1.7 - up to API 23 JDK 1.6 - up to API 20 Additionally, a 64-bit version of the JDK is required to use custom controls in the Android designer.
I wrote a big blog on setup here: http://motzcod.es/post/150380059392/preparing-machines-for-xamarin-cycle if things aren't configure properly.
Try to do a New project at this point and it will re-download all the NuGets and such properly.
As for System.ObjectModel warning, you can remove it from the References and it shouldn't be needed.

Resources