Conditional Compilation in Xamrine.forms for iOS and Android - xamarin

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 ?

Related

How can we add android nugets in Xamarin.forms and not only in Xamarin.Android

I am trying to install the below NuGet in a Xamarin Forms Project(and not on Xamarin.Android project)
Xamarin.Android.Support.core.Utiles
Xamarin.Android.Support.Animated.Vector.Drawable
I want to access the MediaProjectionManager in my Xamarin project class without platform-specific conditions. Please help me with this.
Right now whenever I am trying to install the android related NuGet packages in Xamarin Forms project I am getting the below error.
Error NU1202 Package Xamarin.Android.Support.Vector.Drawable 28.0.0.3 is not compatible with netstandard2.1 (.NETStandard,Version=v2.1). Package Xamarin.Android.Support.Vector.Drawable 28.0.0.3 supports:
- monoandroid60 (MonoAndroid,Version=v6.0)
- monoandroid70 (MonoAndroid,Version=v7.0)
- monoandroid71 (MonoAndroid,Version=v7.1)
- monoandroid80 (MonoAndroid,Version=v8.0)
- monoandroid81 (MonoAndroid,Version=v8.1)
- monoandroid90 (MonoAndroid,Version=v9.0)
Error Package restore failed. Rolling back package changes for .
If I write the below code in the cs file in the Xamarin project and if I try to access the below object from the MainActivity.cs file in the Xamarin.Android project, am getting below error.
The MediaProjection object is not available in XamarinFile. It is not able to access any android related function or object.
#if __ANDROID__
public MediaProjection MediaProjection { get; set; }
#endif
XamarinFile.Instance.MediaProjection = manager.GetMediaProjection((int)resultCode, data);
You are trying to install an Android-specific library into a Xamarin .NET Standard/PCL project which is not compatible. The error itself clearly tells that. If you want to have any platform-specific functionality for your Xamarin Forms application, then you can try to create a custom view for it and write a custom renderer in the native projects. In the corresponding native project, install the desired package and achieve what you want.
Refer to the Xamarin Forms Custom Renderers documentation for more details.
Otherwise, try to create your project as a Shared project instead of .NET Standard project.
Refer to the Shared Project documentation here for more details.

Xamarin create application for android 4 (VS2017 15.5.5)

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.

How to integrate Native ios and android sdk in Xamarin

I have to integrate one third party sdk in xamarin project.
They are providing the native sdk's for android and ios. I need to use them in Xamarin project to develop app for ios and android.
Xamarin offers in depth documentation for linking native libraries.
Linking native library iOS here and Binding a java Library here.
If you want to go further and use these sdk's in Xamarin.Forms you can make a wrapper in each platform dependent project and link them to your Forms project using Xamarin.Forms.DependencyService.
To use Firebase Crashlytics in your application follow the steps:
Install packages: Xamarin.firebase.iOS.Crashlytics and Xamarin.firebase.iOS.Core
Download GoogleService-Info.Plist file and add it to your project.
Set the build action as "Bundle Resource".
Build the project and run.

Building a C++ PCL library and using it in Xamarin.iOS, Xamarin.Android and Xamarin.Mac

I'd like to build a PCL library, starting from an existing C++ code. This code has some dependencies (SDL, which is available as a NuGet package) and I'd like to know if it's feasible to integrate it in a Xamarin solution (which targets Xamarin.iOS, Xamarin.Android and Xamarin.Mac).
More precisely, the code is hosted here : https://github.com/chunying/gaminganywhere/tree/master/ga/client
If so, do I need to use C++/CX language ?

Can not compile after migrating unified api in xamarin forms

We have migrated the xamarin forms project to unified api.
But we have the strange compile error like this:
Could not AOT the assembly '.../iOS/obj/iPhone/Debug/mtouch-cache/Build/Xamarin.Forms.Labs.dll
So I changed the settings in iOS project's options.
In ios Build Tab of Project options(iOS) I changed the "don't link" to "Link all assemblies".
But the app is crashed when it is started.
xamarin version is 5.7.1(build 17).
xamarin forms's version is 1.3.5.6337.
xamarin forms labs's version is 1.0.1.5.
Please help me if you have the experience with this error.
Replace Xamarin.Forms.Labs with XLabs.Forms.
There has been a major refactoring on how the XLabs project is structured so your existing project based on the 1.x.x will break. The reason for the refactoring was simple; separate functionality that does not depend on Xamarin.Forms into different assemblies. This allows the use of functionality like IoC, Serialization and even platform specific services without referencing XF.
To upgrade:
Uninstall any existing Xamarin.Forms.Labs packages from your
project.
Install XLabs.Forms package to your projects (PCL, iOS, Droid & WP). This will update Xamarin.Forms to the latest stable release (1.4.x)
Refactor code to reference the correct namespaces.

Resources