Windows下 ndk 编译程序

环境变量添加 Android 相关设置:

ANDROID_HOME   C:\Users\zhanghb\AppData\Local\Android\Sdk

ANDROID_NDK       C:\Users\zhanghb\AppData\Local\Android\Sdk\ndk\21.1.6352462

创建一个源码目录hello

1. 创建子目录 jni

2. 在 jni 目录创建2个文件,hello.c 和 Android.mk

hello.c

#include 
int main()
{
    printf("Hello World!\n");
    return 0;
 
}

Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:=hello.c
LOCAL_MODULE := helloworld
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

3. 开始编译

进入 hello 目录,执行:

>set NDK_PROJECT_PATH=.
>ndk-build
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-16.
[arm64-v8a] Compile        : helloworld <= hello.c
[arm64-v8a] Executable     : helloworld
[arm64-v8a] Install        : helloworld => libs/arm64-v8a/helloworld
[armeabi-v7a] Compile thumb  : helloworld <= hello.c
[armeabi-v7a] Executable     : helloworld
[armeabi-v7a] Install        : helloworld => libs/armeabi-v7a/helloworld
[x86] Compile        : helloworld <= hello.c
[x86] Executable     : helloworld
[x86] Install        : helloworld => libs/x86/helloworld
[x86_64] Compile        : helloworld <= hello.c
[x86_64] Executable     : helloworld
[x86_64] Install        : helloworld => libs/x86_64/helloworld

 

你可能感兴趣的:(安全开发)