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 <stdio.h>
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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章