I need to use C++17
compliant source files in my Android project. I added my .cpp
files to the src/main/cpp
folder.
After the build, this error appears:
Build command failed.
Error while executing process
/Users/khasan/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with
arguments {-H/Users/khasan/Projects/myapplication/app -B/Users/khasan/Projects/myapplication/app/.externalNativeBuild/cmake/debug/
arm64-v8a -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-21 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/khasan/Projects/myapplication/app/bu
ild/intermediates/cmake/debug/obj/arm64-v8a -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=/Users/khasan/Library/Android/sdk/ndk-bundle -
DCMAKE_CXX_FLAGS=-std=c++17 -fexceptions -frtti -
DCMAKE_TOOLCHAIN_FILE=/Users/khasan/Library/Android/sdk/ndk-
bundle/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=/Users/khasan/Library/Android/sdk/cmake/3.6.4111459/bin
/ninja -GAndroid Gradle - Ninja -DBUILD_TESTING=OFF -DANDROID_TOOLCHAIN=gcc}
-- Configuring incomplete, errors occurred!
CMake Error at /Users/khasan/Library/Android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake:169 (message):
GCC is no longer supported. See https://android.googlesource.com/platform/ndk/+/master/docs/ClangMigration .md.
Call Stack (most recent call first):
/Users/khasan/Library/Android/sdk/cmake/3.6.4111459/share/cmake- 3.6/Modules/CMakeDetermineSystem.cmake:98 (include)
CMakeLists.txt
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "ganikhodjaev.test.myapplication"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++17 -fexceptions -frtti"
arguments '-DBUILD_TESTING=OFF', '-DANDROID_TOOLCHAIN=gcc'
}
}
ndk {
abiFilters 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
}
}
packagingOptions {
doNotStrip '*/mips/*.so'
doNotStrip '*/mips64/*.so'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
}
NDK
version 19. Maybe I connect something wrong?
For Android NDK, llvm/Clang became the default toolchain since r13b and gcc was removed since r18b.
You need to remove
'-DANDROID_TOOLCHAIN=gcc'
and let the build system to select clang by default.Also, cross check ndk revision history and --gcc-toolchain changes and clang migration from gcc.