DllImport in XF project - How to write a .NET Standard project to use platform native library

MatteoPiccioniMatteoPiccioni USMember ✭✭
edited July 3 in Xamarin.Forms

Hello,
I have a X.F. that needs to use native library and .net standard projects.

I add my c library, compiled for iOS (mylib.a) and Android (mylib.so), in the iOS and Android projects in the right places
I made simple tests calling this library from within iOS and Android projects and it works well

For my needs, in my solution I also have a .NET Stardard project, that 'talk' my mylib library.
Unforunately in .NET Standard projects I can't use preprocessing directive, so I am not able to make the right DLLImport declaration for iOS and Android,
for example like that:

#if Android
        [System.Runtime.InteropServices.DllImport("mylib")]
        private static extern int my_c_func(byte[] stato, UInt16 attempts);
#elif iOS
        [System.Runtime.InteropServices.DllImport("__Internal")]
        private static extern int my_c_func(byte[] stato, UInt16 attempts);
#endf

I wich way I should solve my problem?
Thanks

Answers

Sign In or Register to comment.