Search code examples
c#xamarin.formsprinter-control-language

compiling xcode/android libraries into PCL for acces in shared code


I am trying to write an application using a 3rd party library. The 3rd party has made independent APIs for both Android and IOS but nothing in between. I researched PCLs and it seems that the shared code has to be written in C#. I question if it is possible to compile Xcode/Java library into a PCL that I can call in a shared code application. I want to write one app without a bunch of system definitions in my code for system specifics. My end goal is to write as little repeating code as possible.


Solution

  • Unfortunately you cannot do that. Even if the resulting API of the library looks the same on both systems, it is still "native" on both, and the libraries are still two separate assemblies.

    You can utilize binding of Java and Objective-C libraries. This will give you a C# interface to access the native library. Then to use the library from shared (PCL) code, you will need to create a dependency service, that which will require you to create an interface in the PCL and then implement the interface on both platforms. In the platform implementation you can then normally access your generated library as expected. See the documentation on a step-by-step tutorial for this.

    If the library is really exactly the same on both systems, you could share the source code file on both platforms (Add -> Existing item -> Add as Link) or alternatively just wrap the libary to an interface and then use that for access.