如何使用 NDK 定位多个架构? [英] How to target multiple architectures using NDK?

查看:19
本文介绍了如何使用 NDK 定位多个架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Background

I've recently started to develop some code using the NDK, and I've thought of a possible portability problem that could occur while developing using NDK.

The problem

Since NDK uses native code, it needs to be compiled per CPU architecture. This is a problem since the user needs to run the app no matter what CPU the device has.

Possible solutions I've found so far

I've noticed I can modify the file "jni/Application.mk" and use:

APP_ABI := armeabi armeabi-v7a x86

however, I don't know what I should do from this step on. Will the app contain all of the compiled code for each of the CPU architectures and automatically choose the correct one when running itself?

Also, what if there will be another CPU architecture that is unknown?

What will happen if I try to run the app on Google TV, which according to what I remember doesn't support the NDK at all?

Another solution I've found is the multi-apk support. However, I'm not sure I understand it. Does it all mean that you create the same APK, each time with a different configuration? No special automation tool from ADT to help with that?

解决方案

If you don't set APP_ABI at all, or use

APP_ABI := all

in your Application.mk, then ndk-build will build for all architectures supported by your version of NDK. The latest one, to date r8d, will in addition to armeabi armeabi-v7a x86 build also for mips. When another architecture will be released, you will hopefully automatically get the APK built to support it.

When you application is installed on an Android device, the system will automatically choose the matching ABI version and install the correct shared libraries from the APK.

One drawback of this approach is that if the native libraries are big, your "monolithic" APK file may become huge. You can use the multi-APK approach to make user downloads smaller. The official site recommends: You should generally use multiple APKs to support different device configurations only when your APK is too large (greater than 50MB). You should carefully follow the version code guildlines if you choose this route.

Unfortunately, there are no trustworthy prophecies regarding NDK support on Google TV, but there seem to be no technical justification for its current unavailability. If and when it arrives, your ndk-build will take care of it automatically.

UPDATE Here is a simple process to maintain split APK. And by the way, the new Android TV does support NDK.

这篇关于如何使用 NDK 定位多个架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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