简体   繁体   English

如何在Xamarin.Android和Xamarin.iOS上使用dllmap?

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

I'm using Xamarin.Android, have a project set up like so 我正在使用Xamarin.Android,有一个像这样的项目设置

  • Native library for Windows (NativeMethods.dll) 适用于Windows的本机库(NativeMethods.dll)
  • Native library for Android (NativeMethods.so) 适用于Android的本机库(NativeMethods.so)
  • Portable P/Invoke library, DllImport to NativeMethods.dll 便携式P / Invoke库,DllImport到NativeMethods.dll
  • Windows application (uses portable P/Invoke library + Windows native library) Windows应用程序(使用便携式P / Invoke库+ Windows本机库)
  • Android application (uses portable P/Invoke library + Android native library) Android应用程序(使用便携式P / Invoke库+ Android本机库)

Using mono, one could simply use dllmap in App.config to remap any DllImports to NativeMethods.dll to NativeMethods.so 使用mono,可以简单地在App.config中使用dllmap将任何DllImports重新映射到NativeMethods.dll到NativeMethods.so

I tried, but I can't seem to get this working with Xamarin.Android. 我尝试过,但我似乎无法使用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). 我想避免编译两个MSIL P / Invoke库以及两个本机库(Android和Windows各一个)。

Here's what my app.config looks like 这是我的app.config的样子

  <?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. 我在P / Invoke DLL项目,Xamarin.Android应用程序项目中尝试了这个,但它在任何地方都不起作用。 The only reference I found to my issue is this similar one for iOS. 我发现我的问题的唯一参考是类似一个用于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. 如果为Xamarin.iOS执行此操作的解决方案有任何不同,我也会感兴趣,因为这将是我需要定位的下一个平台。

Thanks in advance! 提前致谢!

Use NativeMethods (without extension) as the name of the library. 使用NativeMethods (不带扩展名)作为库的名称。

.NET will automatically append .dll and Mono will automatically append .so when searching for the library. .NET将自动附加.dll ,Mono将在搜索库时自动附加.so

However for iOS you'll need a dllmap (since the library name must be __Internal ) 但是对于iOS,你需要一个dllmap(因为库名必须是__Internal

Source: http://www.mono-project.com/docs/advanced/pinvoke/ 资料来源: http//www.mono-project.com/docs/advanced/pinvoke/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 CustomRenderer 用于 Xamarin.iOS 和 Xamarin.ZE84E30B9390CDB6DZDB6DB2CDB878 中的单个 ContentPage - How to use CustomRenderer for a single ContentPage in Xamarin.iOS and Xamarin.Android 是否可以将Xamarin.IOS或Xamarin.Android代码用于Xamarin Windows Phone开发 - Is It possible to use the Xamarin.IOS or Xamarin.Android code for Xamarin Windows Phone development 无法将Xamarin.Android和Xamarin.iOS添加到PCL - Unable to add Xamarin.Android and Xamarin.iOS to PCL Xamarin.iOS 和 Xamarin.Android 的 NuGet 包缩写是什么? - What are the NuGet package abbreviations for Xamarin.iOS and Xamarin.Android? 在Xamarin.Android/Xamarin.iOS中使用Akavache - Using Akavache in Xamarin.Android/Xamarin.iOS 无法使用Xamarin.Android / Xamarin.iOS创建可移植类库项目 - Can't Create Portable Class Library Project with Xamarin.Android / Xamarin.iOS ML.Net 在 Xamarin.Android 上工作但不在 Xamarin.iOS 上工作:System.Reflection.Emit - ML.Net working on Xamarin.Android but not on Xamarin.iOS: System.Reflection.Emit 如何在Xamarin.iOS中构建自定义UIAlertController? - How can I build custom UIAlertController in Xamarin.iOS? 如何在 Xamarin.iOS 中使用#available / @available - How to use #available / @available in Xamarin.iOS 如何在Xamarin.iOS项目中使用iCarousel - How to use iCarousel in Xamarin.iOS project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM