Resources in obb (zip) file not loading when previously where in Android

Resources from an obb file are unable to load anymore. It worked in version 3.13 but after updating to version 3.17.1 it isn’t working.

FileUtils::getInstance()->fullPathForFilename(strPlist) returns empty.

Digging a bit more I’ve found out that:

in isFileExistInternal in FileUtilsAndroid (CCFileUtils-android)
if (obbfile && obbfile->fileExists(s))
returns false because _data->fileList in ZipUtils is empty. Finally I’ve discovered that:

_data->zipFile = unzOpen(FileUtils::getInstance()->getSuitableFOpen(zipFile).c_str()); // line 540 in ZipUtils.cpp
is NULL so no fileList entry can be added in setFilter(filter) and therefore files are never found in zip (obb).

Cocos2dxHelper.sOBBFile contains all the resources in the obb file.

Any solution to resolve the issue?

Thanks.

Have you created a GitHub issue for this yet? There are a few changes noted here: https://github.com/cocos2d/cocos2d-x/blob/v3/CHANGELOG but I’m not sure if anything effects you. Perhaps this has been broken before 3.17.

I’m creating a GitHub issue.
Not sure when between versions 3.13 - 3.17.1 the loading of obb content files stopped working. I’m unable to find what change from the change log generated the issue.

Thanks.

Thanks. I will ask the team to take a look at it.

Hi,
Has anyone been able to look at it?
Digging more I’ve found out why unzOpen returns NULL, in unzip.cpp line 618:
us.filestream = ZOPEN64(us.z_filefunc,
path,
ZLIB_FILEFUNC_MODE_READ |
ZLIB_FILEFUNC_MODE_EXISTING);
if (us.filestream==NULL)
return NULL; // is returning here although the path is correct

I’ve created the obb (zip) file with the following command:
$ zip -r -n .mp3 main.1.com.sample.zip *

Thanks.

I have same problem here, I was using 3.17 which obb file work properly.

It may be related to this issue that was fixed a while back.

Updated cocos2d-x-3rd-party-libs-bin-3-deps-156.zip and problem solved! Thank you!

1 Like

The problem is that can’t directly open the zip package in android apk (assets/) by fopen() method. I used another method to circumvent this problem. The following is the solution:

Data buffer;
string zipPath = "assets/page1.zip";
string dataPath = "page1/json.txt";
ssize_t size = 0;
Data zipBuffer;
FileUtils::getInstance()->getContents(zipPath, &zipBuffer);
ZipFile* zipfile = ZipFile::createWithBuffer(zipBuffer.getBytes(), zipBuffer.getSize());
auto data = zipfile->getFileData(dataPath, &size);
//    auto data = FileUtils::getInstance()->getFileDataFromZip(zipPath, dataPath, &size);
if (data) {
    buffer.fastSet(data, size);
}

return buffer;

Use remember to release free(buffer)
I hope to solve your problem.