Cocos2dx Android: Get data from file(assets/*) failed

天涯浪子 提交于 2019-12-13 01:54:29

问题


Where do you need to add your images in your Cocos2dx Android project (in Eclipse)?

They're currently in the 'Resources' folder like what is mentioned on Ray Wenderlich's blog, but I get an error when I run it in the emulator: "get data from (assets/myFileName) failed" for each image. I also added these images to the assets folder in Eclipse, and it makes no difference.

It works fine on the iOS side.

Any suggestions?


回答1:


I believe you need to run ./build_native.sh in your android folder before run on Eclipse.




回答2:


So the actual problem wasn't with the building or copying process.

I had a class I made that would apply the correct prefix to a CCSprite if it was an iphone, ipad, etc. And I made some changes to the CCMenuItemImage source code to incorporate this file, but the iOS and Android Cocos2dx files are separate, so the Android project wasn't using the new code, and wasn't adding the correct prefix, so it wasn't finding the image.

Thank you everyone for your answers!




回答3:


You no need to add to the assets folder , when you run ./build_native.sh it will automatically add to the assets folder. Check it build successfully without any errors and then import to eclipse.




回答4:


Try using

const char *path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("testimage.png");

before giving cocos2d-x your filename.




回答5:


This was the same problem I face. Actually I have solved this problem by doing:

  1. Run the ./build_native.sh from cygwin. This step to move the asset needed to android project. Dont forget to chmod 777 -R first to your cocos project, i've got an error because the build_native.sh doesn't have permission to move the assets.
  2. In eclipse, build it again following this tutorial. In that link, it shows how to build the cpp source + cocos2d in eclipse.
  3. Run as android application, then the .apk will be generated.



回答6:


I'm using the Cocos2d-JS version.

If you have an empty JS file that is imported in your project.json, you will get this very error on Android.

In this case, solution is to not have any empty JS files imported.



来源:https://stackoverflow.com/questions/12417748/cocos2dx-android-get-data-from-fileassets-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!