4

I have a problem dealing with the APK expansions. On Java side, I could set up everything I supposed to set, but it seems I can't modify the code properly on c++ side.

Inside the CCFileUtilsAndroid::getFileData function:

if (fullPath[0] != '/')
{
   CCLOG("GETTING FILE RELATIVE DATA: %s", fullPath.c_str());
   pData  = CCFileUtils::sharedFileUtils()->getFileDataFromZip("/storage/sdcard0/Android/obb/com.example.package/main.1.com.example_package.obb", fullPath.c_str(), pSize);
}

But the pData var is always null (if I'm right, this means that it failed to load). What am I missing guys?

Many thanks in advance

(ps: the package is there, and I'm using the right path)

LugaidVandroiy
  • 209
  • 2
  • 17

3 Answers3

10

So, I finally managed to resolve my issue, and it was way easier than I thought. Instead of going with the c++ source modifications, I found a function in the Cocos2dxHelper java class which is the nativeSetApkPath. After investigating the use of it, it turned out that Cocos2dx handles the apk package as a zip file. Since my obb is just a renamed zip file after all, I could use it without any problem. All of my assets were loaded fine, except the sounds. Which requires another quick fix.

Most of the credit goes to a forum post (http://www.cocos2d-x.org/boards/6/topics/11243) and to Irwin Billing, since that was a base I could use for my modifications in the Cocos2dxMusic.java and Cocos2dxSound.java classes.

Also, I had to be sure that the sound assets were not compressed in the zip file (according to the documentations provided by Google).

For that I used the following command on my Mac:

zip -rn .ogg:.mp3:.wav assets.zip assets/

The last thing I'd like to mention is the folder structure. I copypasted and zipped the assets folder, so I have a folder inside my zip file. Which is great, since the apk works the same way, I had to do no more modifications.

Finally my modified source files, just dont forget to go through it, and change some values Cocos2dxHelper.java: http://pastebin.com/RqeYkTkP

Cocos2dxMusic.java: http://pastebin.com/RXjwmEyb

Cocos2dxSound.java: http://pastebin.com/1GfDB6jb

LugaidVandroiy
  • 209
  • 2
  • 17
  • 3
    Note to self: make sure your zip file contains 'assets' folder as root inside the zip, and not your entire path structure /$HOME/path/to/proj/assets/ – Steve T Oct 07 '13 at 03:25
  • Hi LugaidVandroiy.. I am trying to do the same thing but am using Cocos2d. Can you please point me which is file corresponding to Cocos2dxHelper.java in Cocos2d. I am very new to Cocos2d and have very less knowledge bout it. thanks – Sushil Nov 28 '13 at 00:11
  • Hey! As I know, Cocos2d-x is a different project than the original Cocos2d and Cocos2d-iphone. Which version are you using exactly? I could help maybe. – LugaidVandroiy Nov 28 '13 at 12:56
  • @LugaidVandroiy .. I am using Cocos2d for android. I could figure out that in contentHelper.java, I need to setExternalLoader() properly. But am not able to do it. Will highly appriciate if you can give me some pointers or help in this regard. Thanks again – Sushil Nov 29 '13 at 00:35
  • 2
    I worked with your answer for hours and I want to suggest everyone to check into `AndroidManifest.xml`: `` elsewhere nothing works. – ricky.tribbia Aug 22 '14 at 14:41
1

Just a side note, I leave ttf font files in assets/, because Cocos2dxTypefaces load them from AssetManager (AKA the apk file) using native codes.

lk_vc
  • 1,136
  • 20
  • 26
1

Version 2.x is only my opinion. 3.x is not working Cocos2dxHelper.java is.

lennon310
  • 12,503
  • 11
  • 43
  • 61
jangyuk
  • 11
  • 1