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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With