Reputation: 21335
In Android if an C/C++ shared library created using NDK is invoked and it loads a file what is its currently working directory? Thanks
Upvotes: 12
Views: 5138
Reputation: 576
Negative. Native code getcwd() will return '/', which is not the application directory. To let native know where it is, must pass application directory (obtained from Context object) to native deliberately via a native method. Or try to call Context's method with native codes, which is too complex.
Upvotes: 3
Reputation: 101
The current directory is "/", not the application directory:
#include <jni.h>
#include <android/log.h>
char cwd[1024];
if (getcwd(cwd, sizeof(cwd)) != NULL)
__android_log_print(ANDROID_LOG_INFO, "", cwd);
To get the application directory, you need to use JNI calls to Java code, which in turn gets android application directory from Context.
Upvotes: 10
Reputation: 315
Maybe NDK sample at "android-ndk-rxx/samples/two-libs" will give you some useful message.
Upvotes: -3