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