错误如下:
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
.