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

2

8

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:

Pyrogallol answered 4/2, 2019 at 15:47 Comment(0)
P
5

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
Pyrogallol answered 4/2, 2019 at 15:47 Comment(4)
Note that the build system will do this for you in most cases. Both officially supported build systems (ndk-build and CMake) will.Unthread
@DanAlbert Unfortunately many common dependencies (e.g., cURL) do not have CMake scripts that work at all on Android, so we're left to write or find hand-written build scripts instead.Pyrogallol
Yep, in which case something like this is necessary. That's not the average case for Android code though.Unthread
@JonMcClung did you publish an app including 32 as well as 64 bit native library after August 1 2019? Does still accepts apps targeting min sdk version 15?Ammonia
R
4

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

Rriocard answered 6/2, 2019 at 16:33 Comment(1)
Many of the dependencies I use do not support CMake (cURL, boost), so I don't have the luxury of a build tool that automatically selects the right __ANDROID_API__. In fact, I originally tried to set it to 16 for all of them and ran into errors, which is what brought me to ask the question in the first place. Thanks for trying to help, though.Pyrogallol

© 2022 - 2024 — McMap. All rights reserved.