add_library
改成add_executable
,例:cmake_minimum_required(VERSION 3.4.1)
#導入當前目錄下所有的.cpp文件進行編譯
file(GLOB src-files
${CMAKE_SOURCE_DIR}/*.cpp
)
add_executable( # Sets the name of the library.
ShellTool
# Sets the library as a shared library.
#SHARED
# Provides a relative path to your source file(s).
${src-files} )
複製代碼
defaultConfig {
applicationId "com.nani.ipashelldetec"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
//添加-static選項
cppFlags "-std=c++11 -static"
}
ndk{
//選擇須要編譯的架構
abiFilters "x86_64","arm64-v8a"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.10.2"
}
}
複製代碼
3.執行build就能夠在對應目錄找到可執行文件了,選擇對應的架構,通常咱們Linux是x86_64平臺的。android