Android JNI, what is the current working directory for C / C ++ executable code?

On Android, if you use the C / C ++ shared library created using the NDK and download the file, what is its current working directory? Thanks

+7
source share
3 answers

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 for Java code, which in turn gets the android application directory from the context.

+7
source

Negative The generic code getcwd () will return '/', which is not an application directory. To let your family know where it is, you must pass the application directory (obtained from the Context object) to native using your own method. Or try calling the context method with your own codes, which is too complicated.

+1
source

Maybe the NDK example in "android-ndk-rxx / samples / two-libs" will give you a helpful message.

-2
source

All Articles