Home > database >  android ndk: specify APP_ABI with cmake
android ndk: specify APP_ABI with cmake

Time:06-26

I want to compile some c files for my android project. I'm using NDK with cmake. And I want to generate the .so files for all available CPU types. Most of the tutorials online are based on ndk-build, in which they specify the APP_ABI := all in Application.mk file. How can I do the same with cmake? My cmake version is 3.18.1 Thanks.

CodePudding user response:

For a "pure" CMake project, this cannot be done with a single generated build tree.

Assuming you are passing a path to a toolchain file to CMake (with -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake), you should also be passing in an ANDROID_ABI argument. For possible values see here

You're then expected to have a separate build dir for each ABI, something like:

MyProjectDir/
  build_x86_64/
  build_x86/
  build_arm64/
  build_armeabi/
  src/
  ...

If, on the other hand, you are working with a Gradle-managed project, then the ABI is automatically controlled by Gradle and you only need to worry if you don't want to build for all ABIs.

Build your app as normal, and when you get an APK - open it (it's essentially a ZIP archive). Inside it should be a lib directory containing subdirectories for each ABI.

  • Related