Android 应用程序(使用从 NDK 构建的库)可以在 x86 和 x86 上使用吗? ARM平台?
我将构建一个 Android 应用程序,我想在其中使用 C 库。因此,我计划将 NDK 与 SDK 一起使用。 NDK 支持 ARMv5、ARmv7 和 x86 指令集。现在,如果我使用 ARMv5 构建 Android 应用程序,它是否可以在基于 Intel ( x86 ) 平台的 Android 手机上运行(我是否遗漏了什么?)?如果没有,那么我可以通过什么方式构建一个可以在所有 Android 手机上运行的 Android 应用程序(它使用下面的一些 C 库),无论底层平台如何?
维布杰尔
I am going to build an Android application in which I want to use a C library. So, I am planning to use NDK along with the SDK. NDK supports ARMv5, ARmv7 and x86 instruction set. Now, if I build an Android application using ARMv5 , will it run on Android phones based on Intel ( x86 ) platform (am I missing something ?)? If not, then what is the way by which I can build an ANdroid application ( which uses some C libraries underneath ) that can run on all the Android phones irrespective of the underneath platform?
Vibgyor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在 ndk 中使用以下命令为该架构构建 .so。
.so 将出现在相应的目录中,并将在运行时被拾取。
因此,您需要为每个 cpu 构建 NDK 部分。因此,最终您将得到一个适用于 ARM 的 .so 文件,一个适用于 x86 的 .so 文件(也许还有一个适用于 armv7 的 .so 文件)。
两个/三个 .so 文件捆绑在最终的 .apk 中,并且在安装过程中,Android 操作系统会为要安装的设备选择正确的 .so 文件。
因此,如果您有一个 java 部分:它将在所有内容上运行。
如果您有 NDK 部分:您将需要为每个 cpu 平台创建一个 .so 文件,但它们可以/将被捆绑在一起并自动选择,而用户不知道幕后发生了什么。
You need to use the following command in ndk to build .so for the architecture.
The .so will be present in the respective directory and will be picked up at runtime.
So you need to build your NDK portion for every cpu. So in the end you will end up with a .so file for arm, one for x86 (and maybe another one for armv7).
The two / three .so files are bundled in your final .apk, and during installation the Android OS picks the right .so file for the device it's being installed on.
So if you have a java portion: that will run on everything.
If you have a NDK portion: You will need to create a .so file for every cpu platform, but they can / will be bundled together and automaticly picked without the user knowing what's going on behind the scenes.
某些 x86 设备(例如 Samsung Galaxy Tab 2)包含 ARM 模拟层。了解这一点很重要,但您应该在工作中遵循上述建议。如果可能的话,您不应依赖此模拟的原因之一是,性能约为经济代码的 40%。
Some x86 devices, e.g. Samsung Galaxy Tab 2, include an arm emulation layer. This is important to know, but you should follow the advice above in your work. One reason why you should not rely on this emulation if possible is that performance is about 40% of economies code.
最好的方法是为所有平台(armeabi armeabi-v7a mips 和 x86)构建本机库,只需在变量 APP_ABI 中设置“all”即可。
jni/应用程序.mk
在我的例子中,我使用 android-ndk-r9b
注意:如果您要将本机库部署到基于 x86 和 MIPS 的设备,您的应用程序必须面向 Android 2.3(API 级别 9)或更高版本。
AndroidManifest.xml
更多信息: https://developer.android.com/tools/sdk/ndk/索引.html
The best is to build the native library for all platforms (armeabi armeabi-v7a mips and x86), just set "all" in the variable APP_ABI.
jni/Application.mk
In my case, I use android-ndk-r9b
Note: If you are deploying native libraries to x86 and MIPS-based devices, your application must target Android 2.3 (API level 9) or later.
AndroidManifest.xml
More info: https://developer.android.com/tools/sdk/ndk/index.html