CCFileUtils::sharedFileUtils()->getWritablePath() empty on Android!

CCFileUtils::sharedFileUtils()->getWritablePath() empty on Android!
0.0 0


I have successfully used the method CCFileUtils::sharedFileUtils()>getWritablePath in ios, and it works like a charm, however, on Android it always returns an empty string and hence I get a SIGSEGV when I try to write anything.
I have checked the permissions
WRITE_EXTERNAL_STORAGE is present in the manifest.

I have also tried to put in logs in the - the init is done, but on requesting writablePath, it never hits the getCocos2dxWritablePath().

Could someone help me out please? I am stuck at this for so long now!




Dawid, yes, /sdcard works, but cocos2d-x being cross platform should ideally be taking care of this.

Not that I am complaining (I love cocos2d-x!), but I would like to know if there is any setting or method that I need to call before hand so that I can use (or any other method in place of getWritablePath() which would work on both Android and iOS.


What version are you using?
Are you calling it from a different thread?

I’m using 2.1.4 and the only instance where I got the same problem is when I called getWritablePath() on a separate thread.


Oh yes Lance! Good Catch

I am calling it from a different thread - never even thought about it (since it always worked on iOS). I have not tried it out yet, but I think things should work fine if I can pass the path from the thread creator as file write permissions are same for all threads? (Or do you think write permissions are thread specific in general?)


What I did was (kinda hacky, though) save the value on a variable before starting the thread, then whenever I need getWritablePath(), I use the variable instead. The path returned won’t change anyway, lol.


I’m not sure the same will work for me, as I have multiple threads doing the same thing (making use of max simultaneous connections to a host :) ). I will however try to pass it as arguments during creation of thread .
Also, on a side note
I would like to know why this wouldn’t work inside a different thread - I know for sure that jni functions can be called in all threads, and though extending CCObject, its not performing any OpenGL actions, so ideally it should pass….


I had the save problem, because I use CCFileUtils::sharedFileUtils()->getWritablePath() in another thread.
It works on ios but it does not work on android;

My solution is:

when app launch, in the main thread, you use CCFileUtils::sharedFileUtils()->getWriteablePath() to get the path,
then you can re-code the method libs/cocos2dx/platform/android/CCFileUtils.cpp, like this:

string CCFileUtils::getWriteablePath()
if (“”) == 0)
//android c++ code to get the WriteablePath

m_strWriteablePath = “XXXXXXXXXXX”;

return m_strWritablePath;

Then you can use CCFileUtils::sharedFileUtils()->getWritablePath() in any time, any thread.

hope it work, but sorry for my poor english _


Yep, we should save the writable path at beginning.
#2449 is created for it.