jmosesman
jmosesman

Reputation: 726

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

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?

Upvotes: 1

Views: 8569

Answers (6)

Rebs
Rebs

Reputation: 4239

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.

Upvotes: 0

jmosesman
jmosesman

Reputation: 726

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!

Upvotes: 1

Agung Pratama
Agung Pratama

Reputation: 3784

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.

Upvotes: 0

milkplus
milkplus

Reputation: 34267

Try using

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

before giving cocos2d-x your filename.

Upvotes: 0

srikanth chitturi
srikanth chitturi

Reputation: 116

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.

Upvotes: 0

m.ding
m.ding

Reputation: 3182

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

Upvotes: 3

Related Questions