可以在 Android 应用程序中包含/链接和使用为 linux 构建的共享库 (.so) 文件吗? [英] Can a shared library (.so) file built for linux be included/linked and used in an Android application?

查看:10
本文介绍了可以在 Android 应用程序中包含/链接和使用为 linux 构建的共享库 (.so) 文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,我需要在 Android 应用程序中包含 NGSpice 模拟库当然可以使用它.

I am working on a project in which I need to include NGSpice simulation library in an Android application and of course be able to use it.

我尝试使用 SWIG 和 Android NDK 在我的 android 应用程序中包含 NGSpice windows DLL,但结果证明这是不可能的,所以现在我开始考虑将 NGSpice 构建为 Linux 共享库.

I tried including the NGSpice windows DLL in my android application using SWIG and Android NDK, but it turned out that it is not even possible, so now I started to think about building NGSpice as a shared library for linux.

现在我的问题是,我可以在我的 Android 应用程序中使用 NGSpice 的 linux 共享库吗,还是需要以不同的方式构建它才能在我的 Android 应用程序上工作.

And now my question is, can I use the linux shared library for NGSpice as it is in my Android application, or does it need to built differently somehow to work on my Android application.

谢谢.

推荐答案

没有.Android 与传统 linux 通常有两个主要区别:

No. Android typically has two key differences from a traditional linux:

1) 它使用仿生 C 库和动态链接器,而不是 glibc 等更传统的集合.

1) It uses the Bionic C library and dynamic linker, instead of a more traditional set such as glibc.

2) Android 通常在 ARM 或 32 位 x86 处理器(或在极少数情况下为 MIPS)上运行,而您的桌面 Linux 库可能是 64 位或 32 位 x86 代码.

2) Android is typically run on an ARM or 32-bit x86 processor (or in rare cases MIPS), while your desktop Linux library might be either 64-bit or 32-bit x86 code.

如果你构建一个与机器架构和仿生系统库函数和动态链接器兼容的.so,那么它应该是可行的.

If you build a .so compatible with the architecture of the machine and with bionic's system library functions and dynamic linker, then it should be workable.

或者,如果您有兼容架构的东西,但 libc 错误,则可以编写自己的加载程序,以在安全设备上以工作形式将其放入内存,或者在有根设备上运行chroot 中更传统的 linux 用户空间(通常是 Debian 派生的).但这些都不容易集成到 Android 应用程序中 - 对于后者,您几乎肯定必须通过进程间通信来传递工作,而在前一种情况下也可能更容易.

Alternatively, if you have something for a compatible architecture but the wrong libc, it may be possible to write your own loader to get it into memory in working form on a secured device, or on a rooted device it is possible to run a more traditional linux userspace (typically Debian derived) in a chroot. But neither of these would be easy to integrate into an Android application - for the latter you'd almost definitely have to pass work over via interprocess communication, and that might prove easier in the former case as well.

您唯一真正认可的解决方案是使用 ndk 构建系统或 ndk 生成的独立工具链"和库的当前构建系统从源代码重建库.

这篇关于可以在 Android 应用程序中包含/链接和使用为 linux 构建的共享库 (.so) 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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