对不起,以下应该是评论,而不是回答 – 因为我不知道你的代码有什么问题,但是你可以做些什么来弄清楚自己:
这是我最小的Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := HelloJni.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_CPPFLAGS := -std=c++11
NDK_TOOLCHAIN_VERSION=4.8
APP_STL=gnustl_static
这是最小的HelloJni.cpp
#include
#include
void doSomeWork( void )
{
__android_log_print(ANDROID_LOG_DEBUG, "HelloJni", "hello from thread...");
return;
}
extern "C"
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
std::thread t( doSomeWork );
t.join();
return env->NewStringUTF("Hello from JNI !");
}
它在我的Mac上的r9b中构建干净.要检查一件事:运行ndk-build V = 1并确保链接步骤类似于
~/android-ndk-r9b/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ -Wl,-soname,libhello-jni.so -shared --sysroot=~/android-ndk-r9b/platforms/android-17/arch-arm ./obj/local/armeabi/objs-debug/hello-jni/HelloJni.o ~/android-ndk-r9b/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi/libgnustl_static.a -lgcc -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -L~/android-ndk-r9b/platforms/android-17/arch-arm/usr/lib -llog -lc -lm -o ./obj/local/armeabi/libhello-jni.so
并检查命令的输出
~/android-ndk-r9b/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86/bin/arm-linux-androideabi-nm -C ~/android-ndk-r9b/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi/libgnustl_static.a | grep std::thread
这是我得到的:
00000000 T std::thread::_M_start_thread(std::shared_ptr<:thread::_impl_base>)
00000000 T std::thread::hardware_concurrency()
00000000 T std::thread::join()
00000000 T std::thread::detach()