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

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

They are currently located in the Resources folder, for example, about what is mentioned in the Ray Wenderlich blog , but when I run it in the emulator, I get: “I couldn’t get data from (assets / myFileName)” for each image. I also added these images to the resource folder in Eclipse, and that doesn't matter.

It works great on the iOS side.

Any suggestions?

+1
source share
6 answers

So the problem was not in the build or copy process.

I had a class that I made that would apply the correct prefix for CCSprite if it were iphone, ipad, etc. And I made some changes to the source code of CCMenuItemImage to include this file, but the iOS and Android Cocos2dx files are separate, so the Android project did not use the new code and did not add the correct prefix, so it could not find the image.

Thank you all for your answers!

+1
source

I believe you need to run. / build _native.sh in your Android folder before running on Eclipse.

+3
source

You do not need to add to the resource folder when you start. / build _native.sh, it will automatically add to the resource folder. Check it successfully, without errors, and then import into the eclipse.

0
source

It was the same problem that I am facing. Actually, I solved this problem by doing:

  • Run it. / build _native.sh from cygwin. This step is to move the asset needed for the Android project. Remember to first skip chmod 777 -R into your cocos project, I have an error because build_native.sh does not have permission to transfer assets.
  • In eclipse, create it again by following this tutorial . This link shows how to create a cpp + cocos2d source in eclipse.
  • Launch as an Android app, then .apk will be created.
0
source

Try using

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

before giving cocos2d-x your file name.

0
source

I am using Cocos2d-JS version.

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

In this case, the solution should not contain any empty JS files.

0
source

Source: https://habr.com/ru/post/1495255/


All Articles