我需要在我的Android项目中使用符合C++17标准的源文件。我将我的.cpp文件添加到src/main/cpp文件夹中。
构建后,出现以下错误:
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
版本为 19。可能我连接的东西有问题?