문제

I'm just getting started with Android NDK and I saw that most of the open source apps that use Android NDK have their C++ libraries compiled for multiple CPU architectures. Is that really necessary? If it is does that mean that the resulting apk will contain the C++ libraries compiled many times so the apk will get pretty big? And what will happen with the app if someone tries to run it on an CPU architecture that doesn't have a compiled library? Also o good tutorial about how to build C++ libs for android would be appreciated.

도움이 되었습니까?

해결책

It is not necessary to put them all but if you don't you are excluding devices of this architecture. The apk will contain all binaries and the the installer will select the right one at installation so the case with running a binary targeted at another application will not occur(unless we are considering jail broken devices).

NDK package contains all documentation you need(in docs folder) to build native code for Android.

다른 팁

You can build separate APK files for different processor architectures, and Play Store fully supports this. Instead of downloading one "fat" APK, your customers will get only what they really need, see Android Build Separate Apks for Different Processor Architectures.

To perform such build with ant, you can use the following script:

<target name="-pre-build">
    <exec executable="${ndk.dir}/ndk-build" failonerror="true"/>
    <arg value="APP_ABI=${abi}"/>
</target>

and use a batch file to run the loop (I use a simple sed script; sed is available in %NDK_ROOT%\prebuilt\windows\bin\ and on all other platforms):

sed -i -e "s/versionCode=\"\([0-9]*\).]\"/versionCode=\"\11\"/" AndroidManifest.xml 
ant -Dsdk.dir=%SDK_ROOT% -Dndk.dir=%NDK_ROOT% -Dabi=armeabi release
ren %apkfile%.apk %apkfile%_armeabi.apk

sed -i -e "s/versionCode=\"\([0-9]*\).\"/versionCode=\"\12\"/" AndroidManifest.xml 
ant -Dsdk.dir=%SDK_ROOT% -Dndk.dir=%NDK_ROOT% -Dabi=mips release
ren %apkfile%.apk %apkfile%_mips.apk

sed -i -e "s/versionCode=\"\([0-9]*\).\"/versionCode=\"\13\"/" AndroidManifest.xml 
ant -Dsdk.dir=%SDK_ROOT% -Dndk.dir=%NDK_ROOT% -Dabi=armeabi-v7a release
ren %apkfile%.apk %apkfile%_armeabi-v7a.apk

sed -i -e "s/versionCode=\"\([0-9]*\).\"/versionCode=\"\14\"/" AndroidManifest.xml 
ant -Dsdk.dir=%SDK_ROOT% -Dndk.dir=%NDK_ROOT% -Dabi=x86 release
ren %apkfile%.apk %apkfile%_x86.apk

This assumes that android.verisonCode in the manifest file has zero as last digit, e.g. android:versionCode="40260".

Note that there is technically no reason to change versionCode for armeabi and mips variants, but it may be important to keep armeabi < armeabi-v7a < x86.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top