简体   繁体   English

Android OBB / ZIP加载(cocos2dx)

[英]Android OBB/ZIP loading (cocos2dx)

I have a problem dealing with the APK expansions. 我在处理APK扩展时遇到问题。 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. 在Java方面,我可以设置我应该设置的所有内容,但似乎我无法在c ++端正确修改代码。

Inside the CCFileUtilsAndroid::getFileData function: 在CCFileUtilsAndroid :: getFileData函数内:

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). 但是pData var总是为null(如果我是对的,这意味着它无法加载)。 What am I missing guys? 我想念的是什么人?

Many thanks in advance 提前谢谢了

(ps: the package is there, and I'm using the right path) (ps:包在那里,我正在使用正确的路径)

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. 我没有使用c ++源代码修改,而是在Cocos2dxHelper java类中找到了一个nativeSetApkPath函数。 After investigating the use of it, it turned out that Cocos2dx handles the apk package as a zip file. 在调查了它的使用后,结果发现Cocos2dx将apk包作为zip文件处理。 Since my obb is just a renamed zip file after all, I could use it without any problem. 因为我的obb毕竟只是一个重命名的zip文件,所以我可以毫无问题地使用它。 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. 大部分功劳都归功于论坛帖子( http://www.cocos2d-x.org/boards/6/topics/11243 )和Irwin Billing,因为这是我可以用来修改Cocos2dxMusic的基础。 java和Cocos2dxSound.java类。

Also, I had to be sure that the sound assets were not compressed in the zip file (according to the documentations provided by Google). 此外,我必须确保声音资产未在zip文件中压缩(根据Google提供的文档)。

For that I used the following command on my Mac: 为此,我在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. 我复制并压缩了资产文件夹,所以我的zip文件中有一个文件夹。 Which is great, since the apk works the same way, I had to do no more modifications. 哪个好,因为apk工作方式相同,我不得不做更多修改。

Finally my modified source files, just dont forget to go through it, and change some values Cocos2dxHelper.java: http://pastebin.com/RqeYkTkP 最后我修改的源文件,只是不要忘了去通过它,并改变一些值Cocos2dxHelper.java: http://pastebin.com/RqeYkTkP

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

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

只是旁注,我将ttf字体文件保留在assets/ ,因为Cocos2dxTypefaces使用本机代码从AssetManager (AKA apk文件)加载它们。

Version 2.x is only my opinion. 版本2.x只是我的意见。 3.x is not working Cocos2dxHelper.java is. 3.x不工作Cocos2dxHelper.java是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM