Android 应用程序中的 C# .dll 库 [英] C# .dll library in Android app

查看:48
本文介绍了Android 应用程序中的 C# .dll 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Monodroid 开发一个 android 应用程序.我对手机应用程序很陌生,所以对一些事情感到困惑:

I'm currently using Monodroid to develop an android app. I'm rather new to phone apps so am confused over a couple things:

  1. Android 库的定义是什么?我使用 Mono 模板创建 android 库:为 Android 类库创建 Mono => 编写代码并构建到 .dll => 使用 Visual Studio 中的模拟器运行,它在模拟器中运行良好.但是 .dll 文件是 android 库吗?或者它在模拟器上工作之前被 Mono 转换,'REAL' android 库应该是 JAR?

  1. What by definition is an android library? I use the Mono template to create android library: Create a Mono for Android Class Library => write the code and build into .dll => run with emulator from Visual Studio and it works fine in the emulator. But is the .dll file a android library? Or it is converted by Mono before working on the emulator and the 'REAL' android library should be JAR?

我可以直接使用我用 C# 编写的定义的 .dll 来制作这个应用程序吗?我通过在我的 android 应用程序中直接引用它在 Mono 中进行了尝试,它正在构建,没有错误.但是当模拟器运行这个应用程序时,它会卡住(仍然没有错误) - 在 Android 应用程序项目中使用 c# .dll 的正确方法是什么?

Can I directly use my defined .dll written in C# to make this app? I tried it in Mono by directly referencing it in my android app and it is building, no errors. But when the emulator run this app, it get stucked (still no error) - what is the right way to use c# .dll in Android app project?

我意识到有很多话题在讨论 c# 和 android 之间的链接以及关于单声道,但在阅读后我仍然无法解决这个库引用问题,所以如果有人能提供任何提示/想法将不胜感激

I realize there are quite a couple topics discussing the link between c# and android and about mono but after reading I still cannot get around with this library referencing problem so if anyone could offer any hint/thoughts would be most appreciated

推荐答案

  1. 生成的 DLL 是根据 Mono for Android 配置文件编译的,它基于Moonlight(Mono 对 Silverlight 的实现).在运行时,.NET 代码直接针对 Mono 运行时运行,该运行时作为 您的应用程序的一部分.当 .NET 代码从 Java 端(例如 Java.Lang.Object)子类化某些内容时,Mono for Android 生成 可调用的包装器 来处理运行时之间的通信.
  2. 从技术上讲,您可以在 Mono for Android 应用程序中使用普通的 .NET DLL,但我不建议这样做.Mono for Android 公开的配置文件比完整的 .NET 框架小得多(甚至不完全等同于 Silverlight 的配置文件),因此如果您的 DLL 引用了 Mono for Android 中没有的方法,您的应用程序将崩溃.相反,我建议为您的应用程序创建一个单独的类库,并使用文件链接跨项目共享源文件.我的博客文章在这里 包含如何执行此操作的示例.
  1. The DLL generated is compiled against the Mono for Android profile, which is based on Moonlight (Mono's implementation of Silverlight). At runtime, .NET code is run directly against the Mono runtime which runs as part of your application. When .NET code subclasses something from the Java side (e.g. Java.Lang.Object), Mono for Android generates callable wrappers to handle communication between runtimes.
  2. Technically you can use a normal .NET DLL in your Mono for Android application, but I wouldn't recommend it. The profile exposed by Mono for Android is much smaller than that of the full .NET framework (and isn't even completely equivalent to that of Silverlight), so if your DLL references a method that isn't found in Mono for Android, your application will crash. Instead, I would recommend creating a separate class library for your application, and share source files across projects using file linking. My blog post here contains an example of how to do that.

这篇关于Android 应用程序中的 C# .dll 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆