问题
From what I understand, native code on Android is code that works directly with the processor of a specific device. So if I wanted to take advantage of a certain processor I would use native code.
But what happens if I want to make an app that contains native code, but targets multiple processors?
Do I have to make multiple apps, one for each architecture? Or is there a way to put multiple version of the native code in one app picking the one matching the processor of the device it runs on?
回答1:
The Android Native Development Kit is a suite of cross compilers and support libraries which can be used to produce shared object (.so) files targeting one or more of the officially supported Android architectures.
The Android application package (.apk) specialized zip file format allows inclusion of distinct native libraries for more than one architecture.
If you refer to the NDK documentation, you will see that there is a project configuration file which you can use to specify which architecture(s) your native code should be compiled to support.
回答2:
This is usually referred to as cross compiling. Ie, you need a compiler than compiles X, your current code, for Y. It generates code for CPU Y, not X as is the usual case.
回答3:
You need to target multiple CPU architecture only if you are developing a NDK application. Create a file named "Application.mk" under the jni folder. Add this parameter APP_ABI= Example : APP_ABI:=x86 armv7eabi mips or you can all do this APP_ABI:=all ( in which it would create the apk for all supported architecture) but doing this you would generate a FAT binary and google play will take care of filtering the corresponding apk for different underlying architecture when the user installs your app.
来源:https://stackoverflow.com/questions/23412241/how-can-android-native-code-target-multiple-processor-types