简体   繁体   中英

Does Android's new 64-bit requirement mean the new minimum API level is 21 for apps with native code?

Consider the following:

  • Typically, developers will set the minSdkVersion to 16 because this covers over 99% of devices ( 1 ).
  • However, on August 1, 2019, Android will require all apps to offer 64-bit versions ( 2 ).
  • Furthermore, the NDK API level (set with -D__ANDROID_API__ ) must be equal to the minSdkVersion ( 3 ).
  • Finally, Android devices running on arm64-v8a do not support any lower than API level 21 ( 4 ).

I've tried to do research to figure out how all of this stuff works -- until now I've mostly been hacking my way through just trying to get dependencies to build in order to port my C++ library to Android -- so forgive me if I'm missing something quite obvious. But it seems to me that the above indicates that apps built with the Android NDK will have to target a minimum of API level 21 starting August 1, 2019. Is this correct?

References:

In the process of my research, I think I found the answer. Please feel free to add a better answer if this one is wrong.

The minimum API level of 21 for 64-bit architectures is due to the fact that Android simply did not support 64-bit before then . By using conditionals in your build scripts and/or makefiles, you can specify the API level as 21 for the 64-bit architectures and still go as low as 16 for the 32-bit ones. In this way you will meet Google's requirements and still provide as much compatibility as you did before. Here's a snippet from one of my own scripts:

case "${ABI}" in
  armeabi-v7a | x86)
    API_LEVEL=16
    ;;
  arm64-v8a | x86_64)
    API_LEVEL=21
    ;;
  *)
    echo >&2 "Invalid ABI ${ABI}"
    exit 1
    ;;
esac

Simply compile and include 64bit versions of same 32bit native libs that you have in apk. Leave min SDK version as before.

If app runs on API < 21, it won't see 64bit native libs and it will work with 32bit versions as it did before. On API 21+ the device may use 64bit libs depending on CPU.

Cmake build system will automatically choose correct ndk library to link with from minSdkVersion in build.gradle, so you don't need to care much about setting up build process.

More info: https://developer.android.com/ndk/guides/cmake

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM