Question

I'm porting a C++ Linux application to Android using NDK and testing using the emulator. The application tries to create an /etc/myApp directory and fails because the component /etc does not have the necessary write file system permissions required to create.

Should my application be able to create such a directory? I used adb to inspect and try to make the directory from the shell and it fails too:

mkdir failed for myApp, Read-only file system

Does the file system being read only in adb mean it is also read-only for my application?

Can my application expect to create this directory and if not, is there another location that is more appropriate?

Was it helpful?

Solution

No, you should not be able to do that. Android apps are not permitted to write to system directories.

You should probably create this directory within your app's private storage area. Generally it is best to discover the path of that from Java (don't hardcode it) and then pass it through to the native side.

Depending on your needs for the file, the ExternalStorage might also be an option, especially during development where you might need to easily modify it manually - though keep in mind that others things will be able to change it there, too. Again, you should determine the path on your particular device in Java and then pass that through to the native code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top