Issue
I have been trying to compile a C library for Android armeabi-v7a using the following setup:
Then I used sdkmanager to install
- build-tools 34.0.0
- platforms android-34
- platform-tools
- ndk 26.1.10909125
All that can be found in /opt/android/
and /opt/android/ndk
...
I'm using a CMakeLists.txt file which contains the following bits of configuration:
set(CMAKE_SYSTEM_NAME Android)
set(ANDROID_NDK_VERSION "26.1.10909125")
set(ANDROID_ABI "armeabi-v7a")
set(ANDROID_HOME "/opt/android")
set(ANDROID_NDK "${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}")
set(ANDROID_PLATFORM "android-34")
set(ANDROID_ARM_NEON ON)
set(CMAKE_SYSTEM_VERSION 34)
set(CMAKE_ANDROID_ARCH_ABI "${ANDROID_ABI}")
set(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake")
set(CMAKE_ANDROID_NDK "${ANDROID_NDK}")
And CMake generation fails with the following error:
-- Android: Targeting API '34' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
CMake Error at /usr/share/cmake-3.22/Modules/Platform/Android-Initialize.cmake:97 (message):
Android: The system root directory needed for the selected Android version
and architecture does not exist:
/opt/android/ndk/26.1.10909125/platforms/android-34/arch-arm
Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/CMakeSystemSpecificInitialize.cmake:21 (include)
CMakeLists.txt:5 (project)
What I don't get is why CMake is looking for the platforms
dir in ndk
when sdkmanager
seems to install everything at the root of ANDROID_HOME
(e.g. /opt/android
). Also there doesn't seem to be any arch-arm
dir in /opt/android/platforms/android-34
...
Any know incompatibility with these versions? Or am I missing something obvious?
Thanks!
Solution
Following @Tsyvarev's advice, replacing:
set(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake")
... by:
ìnclude("${ANDROID_NDK}/build/cmake/android.toolchain.cmake")
... did the trick for me.
Answered By - Alex Answer Checked By - Mary Flores (WPSolving Volunteer)