Chanon
Chanon

Reputation: 393

For Android does CMAKE_SYSTEM_VERSION mean the minimum api level or the target api level?

When using CMake to build for Android, does CMAKE_SYSTEM_VERSION correspond to the minimum api level or the target api level?

Upvotes: 5

Views: 3289

Answers (1)

Alex Cohn
Alex Cohn

Reputation: 57173

It's the version of the operating system for which CMake is to build. CMake sets it to the Android API level of the target platform. Usually, we set CMAKE_ANDROID_API instead of manipulating CMAKE_SYSTEM_VERSION directly.

Unfortunately, the NDK toolchain file, which is used by the Android gradle plugin we all use with Android Studio, uses an entirely different set of variables, and sets this to 1 to "Inhibit all of CMake's own NDK handling code". It expects ANDROID_PLATFORM instead.

At any rate, your question about minimum vs. target API level is very important. Unlike Android SDK, the NDK platform support is not backwards compatible. With Java, the best practice is to set the target API as high as possible (and also compile using the latest available SDK), and carefully use the APIs that may be unavailable on older devices.

With C++, we must work differently. Even the latest NDK r18 has 'platforms' going back to android-16, so that you could build your C++ code to run on this older system, too. In terms of Android SDK, this corresponds to minSdkVersion.

Upvotes: 4

Related Questions