It's not safe to always use the latest available API level
The README contains the following:
If you want to create a standalone toolchains (i.e. you're not using
ndk-build), do the previous step, and then follow this guide. You will want to specify which API level you want to use. It is safe to always use the latest available, even if you are targetting older devices.
Surely this can't be correct. If you build against a newer API level, then configure scripts and the like will detect and use any functions which are available in the headers for that level. Then when you try and run your program on an older level where those functions aren't available, you'll get a dynamic linker error.
Instead, when creating a standalone toolchain, you should select the same API level as your app's minSdkVersion.
Hey @mhsmith,
It's been a while since I haven't worked on this project, but I definitely remember about the NDK not being backwards compatible at all. Details might be fuzzy, but it's something like the following:
- Some "standard" functions (I remember something like standard lib math functions) are only declared but not implemented in older API levels. Instead, the older versions of Android provide them at runtime, such that everything runs smoothly.
- However, in newer API levels, those functions are implemented in the NDK, and won't be available at runtime on the phone.
- Therefore, if you compile with an older API level NDK, your binaries will not contain the functions' implementation. If you run your binaries on older phone, they'll be available and everything will run. If you run your binaries on newer phones, they'll be missing and fail.
- If you instead compile on newer API level NDK, your binaries will contain the functions' implementation. Thus they will run fine no matter the phone version.
Well, the current NDK documentation definitely recommends matching the minSdkVersion. If you can remember where you got that information then I'd be interested to see it.
This may have something to do with the following, but it's hard to tell. In any case, if the recommendation has changed you should follow that. If you encounter any issues doing so, please report back for future reference 😃