关闭

android NDK如何解决Please define the NDK_PROJECT_PATH variable to point to it

标签: NDK_PROJECT_PATH def如何编译NDKAndroid NDK Could no
1386人阅读 评论(1) 收藏 举报

从Google android官网下载最新的android ndk安装包android-ndk-r15b,自己配置环境使用ndk-build编译出现如下错误

$ ndk-build 
Android NDK: Could not find application project directory !    
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.    
/home/用户路径/android-ndk-r15b/build/core/build-local.mk:151: *** Android NDK: Aborting    .  Stop.

原来最新的NDK使用命令行编译需要制定项目路径,Android.mk,Application.mk文件路径

ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk APP_BUILD_SCRIPT=Android.mk

注意:NDK_PROJECT_PATH=.  后面是一个英文句号“.”,表示当前路径

重新编译就可以了

$ ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk APP_BUILD_SCRIPT=Android.mk
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.    
[armeabi] Compile++ thumb: HelloJni <= com_demo_Hello.cpp
[armeabi] StaticLibrary  : libstdc++.a
[armeabi] SharedLibrary  : libHelloJni.so
[armeabi] Install        : libHelloJni.so => libs/armeabi/libHelloJni.so
[armeabi-v7a] Compile++ thumb: HelloJni <= com_demo_Hello.cpp
[armeabi-v7a] StaticLibrary  : libstdc++.a
[armeabi-v7a] SharedLibrary  : libHelloJni.so
[armeabi-v7a] Install        : libHelloJni.so => libs/armeabi-v7a/libHelloJni.so
[x86] Compile++      : HelloJni <= com_demo_Hello.cpp
[x86] StaticLibrary  : libstdc++.a
[x86] SharedLibrary  : libHelloJni.so
[x86] Install        : libHelloJni.so => libs/x86/libHelloJni.so

究其原因,谷歌的亲儿子android studio现在高度集成了NDK,所以在编译策略上有所改变,所幸改变不大。

Hello.java

package com.demo;

public class Hello {
    public native static void native_HelloWorld();
}

com_demo_Hello.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_demo_Hello */

#ifndef _Included_com_demo_Hello
#define _Included_com_demo_Hello
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_demo_Hello
 * Method:    native_HelloWorld
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_demo_Hello_native_1HelloWorld
  (JNIEnv *, jclass);

#ifdef __cplusplus
}
#endif
#endif
com_demo_Hello.cpp

#include "com_demo_Hello.h"

#include <android/log.h>

#define TAG "HelloJni"

/*
 * Class:     com_demo_Hello
 * Method:    native_HelloWorld
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_demo_Hello_native_1HelloWorld
  (JNIEnv * env, jclass clazz) {
    __android_log_print(ANDROID_LOG_VERBOSE, TAG, "Hello, World.");
}

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := libHelloJni
LOCAL_C_INCLUDES := com_demo_Hello.h
LOCAL_SRC_FILES := com_demo_Hello.cpp

LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)

Application.mk

 APP_ABI := armeabi armeabi-v7a x86

NDK谷歌编译官网

https://developer.android.com/studio/projects/add-native-code.html#new-project

1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:110479次
    • 积分:1203
    • 等级:
    • 排名:千里之外
    • 原创:37篇
    • 转载:0篇
    • 译文:3篇
    • 评论:30条
    最新评论