How to use obb extension file?

Hello,

I am using cocos2d-x 3.14.1 with C++.
I saw CHANGELOG of v 3.12 that [HIGHLIGHT] support obb extension on Android
So may i know how to use that in C++? there is no cpp-test for that.

It seems relative easy.

Just create a main.VERSIONCODE.PACKAGENAME.obb file. Put it into /sdcard/Android/obb/packageName and it will be used instead of the assets folder. This file should be installed while installing from the PlayStore. Currently I found no build-in download routine, if the user deleted this file manually.

Another issue is, that you always have to update (or rename) your OBB file with the APK. This could also be improved, because the user has always to download the big package in case of an update. There is now way to use OBB files with lower versionCodes, yet.

The cocos team can’t fix it, because they have no access to the PlayStore. So the community (we) have to build a good working solution in the future.

1 Like

You should consider OBB only If you’re unable to host your excess data (>100MB) elsewhere on your own whether through another service or your own server and have your game use the various asset management classes in cocos2d-x.

It requires extra work during publishing, doesn’t allow easy modification like simple changing a manifest file on your server would, etc. It may be slightly easier in the short-term to set up since you don’t have to host anything, but in the long-term it will likely be more of a pain than not.

Also with your own hosted data it would be fully cross-platform. Otherwise on iOS you’ll need to also manage and setup the workflow to use Apple’s On-Demand Resource capabilities.

It’s mostly a personal preference, of course, and YMMV :smiley:
2c

Hi guys,

@smitpatel88, there are two options exist to work with OBB file:

  • native OBB created by jobb tool (not encrypted, because jobb tool is buggy)
  • OBB/ZIP file (when obb file is just a ZIP archive renamed to be a file with .obb extension)

Cocos expects that you will work with OBB/ZIP. It’s not intended to support native OBB format. But it’s still possible to work with it. Native OBB mounts into the Android file system so it’s possible then work with it using POSIX fopen, fwrite, fread functions. Also the native OBB format has no option to compress your data inside it.

Hey @mars3142, it looks like we are at the point when we need this feature when Cocos app could work with the same old version of OBB file after updated .apk was uploaded to Google Play and VersionCode was increased.
We see that now Cocos uses current .apk VersionCode to compose a name for .obb file that makes impossible to work with the same version of .obb file after .apk was updated. I offer to discuss possible best options how to implement this feature. Probably it’s better to create a new topic for that?

thanks

1 Like

Hi,

I have created a obb & put it in the folder now how to unzip it & get the writable path… I have added the read/write permissions.

As I wrote “it will be used instead of the assets folder” (or added - can’t remember it). So you can access your files (within the zip) like files in your asset folder. No need to do special voodoo, because cocos does everything for you.

Ok… thanks
i got it working…

1 Like

@jugnu @mars3142
I am testing one game with obb file
Now problem is in few devices its not running, its crashing. Actually i putted log at java side and it says obb file not exist. Also in one device its running fine if i put obb file in phone-memory, but in sdcard its crashing.
In Cocos2dxHelper.java i found this line

String pathToOBB = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/obb/" + Cocos2dxHelper.sPackageName;

Dont this line should get obb whereever its located in device? or it will work when downloaded from play-store?
Any help will be great.

Did you check the pathToOBB content? Maybe it’s wrong. And what the name of the OBB-file?

pathToOBB : /storage/emulated/0/Android/obb/package_name
OBB file name : main.1.package.name.obb
It works in one device but only in phone-memory, if i put into sdcard then its not working.
We tried both install-location:'auto' & install-location:'preferExternal' if that matters.

What’s the Android version? in older versions you need read/write access to the sdcard, this is removed in current versions because the /Android/data and /Android/obb folder are app specific and that’s why it’s a bad idea to block access :wink:

Is that right, that your packageName is one time with underscore the the other is with dot? I the obb (main.1.*.obb) file within the pathToOBB? The packageNames should both written the same way (case sensitive and with the same underscores).

obb filename was correct only.

We are checking into 5.1, 6.0, 7.0 & 7.1.2
So now everything is working, we were making mistake while copying obb file (some Windows cache memory problem though while transferring through data cable)
Only problem is now that its not working if we put into sdcard, will this be taking care by play store?
Edit:
We had added read/write permission, then its working for internal memory. But still not working for sdcard.

What do you mean by “internal memory”? The obb folder is always on sdcard (afaik - but I only use Phones without physical sdcards).

Internal memory means “Internal shared storage”.
for physical sdcard not working.

App or OBB file? Where does the playstore store the obb file?

App not working if i put obb into external sdcard.

I dont know. I am trying to find answer but no luck so far.
After that problem will be solved.

Hello, I got error when upload obb file to google play too .
When I test in my phone , it run but when I upload apk to store and download app to my phone , it crash , black screen . I don’t know what happen , but I think got problems with read obb file . I check in Android/obb , have file obb but maybe app don’t read it. Do you have any solution?

Sorry my bad English .

@BennyNguyen
Did you find solution?

Hi smitpatel88,
I can’t find any solution yet , I comeback with version 3.11.1. In 3.11.1 , my old project is running well. I will try find solution for version 3.16 later. Thank you.

Do you mean in 3.11.1 obb is working but not in 3.16?