Android - Can't open file file in assets folder

I generated a project with generate_android_project.sh and I am building it under OSX with build_native.sh.

I have added a file to my assets folder but I can’t get it to open. I have verified that the file (bike.json) is in my .apk in the assets folder.

FILE* fp = fopen(“assets/bike.json”, (const char*)“rt”);

fp is always NULL.

This is on device or emulator. I have tried uninstalling the app, full build, etc. This isn’t making me feel very smart :frowning:
Thanks,
p

I haven’t tried working with files yet, but I’m pretty sure you should utilize CCFileUtils::getFileData to get access to files in the APK.

Absolutely right, files in assets folder moved to zip archive during build, so you cannot read them with usual fopen. But you can use CCFileUtils::getFileData for any file.

However fp returns NULL because path assets/bike.json doesn’t exist: it’s relative path, but application working directory isn’t set to root of APK.

dot squid wrote:

I haven’t tried working with files yet, but I’m pretty sure you should utilize CCFileUtils::getFileData to get access to files in the APK.

Thanks guys. I have switched to CCFileUtils::getFileData and b2dJson is much happier now = )