Download Android OBB / ZIP (cocos2dx)

I have a problem with APK extensions. On the Java side, I could configure everything that I had to install, but it seems that I cannot correctly change the code on the 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 pData var is always null (if I'm right, that means it doesn't load). What will I miss guys?

Thank you very much in advance

(ps: there is a package, and I am using the correct path)

+4
source share
3 answers

So, I finally managed to solve my problem, and it was much easier than I thought. Instead of coming with changes to the C ++ source code, I found a function in the java class of Cocos2dxHelper class, which is nativeSetApkPath. After studying its use, it turned out that Cocos2dx processes the apk package as a zip file. Since my obb is just a renamed zip file, I could use it without any problems. All my assets were loaded perfectly, except for the sounds. This requires another quick fix.

Most of the credits are related to the forum post ( http://www.cocos2d-x.org/boards/6/topics/11243 ) and Irwin Billing, as this was the base that I could use for my modifications in Cocos2dxMusic.java and Cocos2dxSound.java.

In addition, I had to be sure that the audio assets were not compressed in a zip file (according to the documentation provided by Google).

To do this, I used the following command on my Mac:

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

The last thing I would like to mention is the folder structure. I copied and archived the resource folder, so I have a folder inside my zip file. This is great, since apk works the same way, I didn't have to make any changes anymore.

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

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

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

+10
source

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

+1
source

Version 2.x is just my opinion. 3.x does not work Cocos2dxHelper.java is.

+1
source

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


All Articles