Shadab Ansari Shadab Ansari - 5 months ago 34
Android Question

NDK not identifying certain header files like <mutex> and <future>

I am trying to integrate C++ files into my android project.
I tried using Android Studio's ndk feature but I got several issues. So I prevented Android Studio from creating its own Android.mk file by making the following changes in my .gradle file -

sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
}


And I created a gradle task to compile my library files.

task ndkBuild(type: Exec) {
commandLine ndk_build_path, '-C', file('src/main/jni').absolutePath
}

tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}


where "ndk_build_path" is defined in gradle.properties file

ndk_build_path=/Users/shadabunique/Library/Android/sdk/ndk-bundle/ndk-build


The platform I'm using is Mac.

The header files in my C++ files are -

#include <stdio.h>
#include <iostream>
#include <unistd.h>
#include <vector>

#include <ctime>
#include <sys/time.h>
#include <cmath>
#include <queue>
#include <mutex>
#include <future>


I also created Application.mk file with contents -

APP_ABI := all
APP_STL := gnustl_static
APP_STL :=stlport_static


I have put all the C++ files, Android.mk and Application.mk files in src/main/java/jni folder.

I am getting the following errors -

mutex: No such file or directory
future: No such file or directory


Please help !

Answer

I solved the issue by making the following changes-

Android.mk -

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

LOCAL_MODULE := myLib
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libmyLib.so
LOCAL_LDLIBS += -llog

include $(PREBUILT_SHARED_LIBRARY)

Application.mk

APP_ABI := all
APP_STL := gnustl_static
APP_STL :=stlport_static
APP_STL :=c++_static

Hope someone could get some help with this.