Forum Cross Platform with Xamarin

How do I structure my app to ensure cross-platform functionality?

Hey I'm a Xamarin beginner who is a bit confused on how to structure my app to ensure cross-platform functionality while writing the smallest amount of code necessary. I have a library written in C and when using this library previously I would go the NDK route(for android), I now have to use the library for my Xamarin.Android and Xamarin.ios app. I want to know what the best way of achieving this goal is. Do I create a shared library or a PCL? Do I find a way to compile the library into a dll and just include in the Xamarin project? Thanks.

Best Answer

  • DaveHuntDaveHunt US ✭✭✭✭✭
    Accepted Answer

    You would need to compile the library separately for Android and iOS, then include the Android version in your Android project and the iOS one in your iOS project. There's no way to put platform-native code into a PCL so that's not an option.

    A shared library won't work either because you have to compile the iOS version with Xcode and the Android version with Android NDK.

    Then you would have to use P/Invoke to call any functions in the library.

    Given total freedom, I'd rewrite the library in C# and be done with it.

Answers

  • DaveHuntDaveHunt USMember ✭✭✭✭✭
    Accepted Answer

    You would need to compile the library separately for Android and iOS, then include the Android version in your Android project and the iOS one in your iOS project. There's no way to put platform-native code into a PCL so that's not an option.

    A shared library won't work either because you have to compile the iOS version with Xcode and the Android version with Android NDK.

    Then you would have to use P/Invoke to call any functions in the library.

    Given total freedom, I'd rewrite the library in C# and be done with it.

Sign In or Register to comment.