简体   繁体   中英

How can I use dllmap on Xamarin.Android and Xamarin.iOS?

I'm using Xamarin.Android, have a project set up like so

  • Native library for Windows (NativeMethods.dll)
  • Native library for Android (NativeMethods.so)
  • Portable P/Invoke library, DllImport to NativeMethods.dll
  • Windows application (uses portable P/Invoke library + Windows native library)
  • Android application (uses portable P/Invoke library + Android native library)

Using mono, one could simply use dllmap in App.config to remap any DllImports to NativeMethods.dll to NativeMethods.so

I tried, but I can't seem to get this working with Xamarin.Android. I'd like to avoid compiling two MSIL P/Invoke libraries as well as two native ones (one each for Android and Windows).

Here's what my app.config looks like

  <?xml version="1.0" encoding="utf-8" ?>
  <configuration>
    <dllmap dll="NativeMethods.dll" target="NativeMethods.so"/>
  </configuration>

I tried this in the P/Invoke DLL project, the Xamarin.Android application project but it doesn't work anywhere. The only reference I found to my issue is this similar one for iOS. Has anyone encountered/solved this issue? What am I missing? I'd also be interested if the solution to do this for Xamarin.iOS was any different, because that will be the next platform I need to target.

Thanks in advance!

Use NativeMethods (without extension) as the name of the library.

.NET will automatically append .dll and Mono will automatically append .so when searching for the library.

However for iOS you'll need a dllmap (since the library name must be __Internal )

Source: http://www.mono-project.com/docs/advanced/pinvoke/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM