• We Android developers usually compile NDK projects into dynamic libraries for APK use. Sometimes we may need to compile them into executable files under Linux. This can also be done by connecting to a remote server through VS.
  1. Inside the CMakeListsadd_libraryInstead ofadd_executableExample:
Cmake_minimum_required (VERSION 3.4.1 track)# import all. CPP files in the current directory to compile
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} )

Copy the code
  1. Modify the defaultConfig node in build.gradle
defaultConfig {
        applicationId "com.nani.ipashelldetec"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"ExternalNativeBuild {cmake {// Add -static option cppFlags"-std=c++11 -static"} NDK {// Select the schema abiFilters to compile"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"}}Copy the code

3. Run build to find the executable file in the corresponding directory, select the corresponding architecture, generally our Linux is x86_64 platform.