Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to include Android.Support.v4 in Xamarin Forms (iOS)?

I am using Visual Studio For Mac. My Xamarin Forms project is quite large and contains many content pages. Some of them will be only used in android project and some of them only used in iOS project. There is no problem when I compile the project into android. However, when I want to compile the project into iOS, it seems like did not accept anything related to android. Please refer to the screenshot. There is no way I can include the android specialised reference and compile into iOS project. So, any idea to deal with this? Maybe there is a way to force build the iOS project no matter what? The error from the screenshot is from the page that will be only used in android. So what I can do for now is delete the page when I want to compile as iOS and recreate the page when I want to used it for android. But there are plenty of them, it is too heavy for me to do this every time. Please help.

Answers

  • Dinesh_OfficialDinesh_Official Member ✭✭✭

    @ASolute_dev , It seems like you have commonly referenced this file in both Android and iOS project with AddAsLink option.

    For Android project, there won't be any problem until you don't have iOS references say using Xamarin.iOS like that.

    In iOS project, you can't refer the Android support libraries at any cause because both are different platforms.

    To resolve this error, i suggest you to use DefineConstants for both project .cs file and split them with conditional compiler.

    For Android :

    For iOS :

    `#if Android
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;

    elif iOS

    endif

    `
    Note: Make sure you have to add same name in each Configuration say Debug CPU, Release CPU, Debug *86 etc.,

Sign In or Register to comment.