您的位置:首页 > 编程语言 > C语言/C++

Android JNI: Can't include C++ headers like vector or string...

2016-04-22 09:24 387 查看
错误如下:

fatal error: string: No such file or directory
#include <string>
^
compilation terminated.
修正:

第一步:

在 $PROJECT_DIR/jni/Application.mk: 加入
APP_STL                 := stlport_static


第二步:

$PROJECT_DIR/jni/Android.mk:
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.cpp
LOCAL_LDLIBS    := -llog

include $(BUILD_SHARED_LIBRARY)


第三步:

$PROJECT_DIR/jni/hello-jni.cpp:
#include <string.h>
#include <jni.h>
#include <android/log.h>

#include <iostream>
#include <vector>

#define  LOG_TAG    "hellojni"
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

#ifdef __cplusplus
extern "C" {
#endif

// Comments omitted.
void
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
std::vector<std::string> vec;

// Go ahead and do some stuff with this vector of strings now.
}

#ifdef __cplusplus
}
#endif


然后
ndk-build
clean && ndk-build
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: