[Cocos2D-X V3] has anyone managed to create an Android expansion?

I was wondering if anyone has managed to use obb expansion files on Android with Cocos2D-X V3 and above ?

I have done this before on previous version of Cocos2D-X by editing Cocos2dxHelper.java as follows

Replace

Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);

With

Cocos2dxHelper.nativeSetApkPath(Environment.getExternalStorageDirectory() + "/Android/obb/" + pContext.getPackageName() + "/main." + Settings.EXPANSION_VERSION + "." + pContext.getPackageName() + ".obb");

But this does not work any more.

Does anyone have any ideas why this no longer works and what to do instead ?

Thanks for any help

Hi,

It would be great if anyone post solution.

Thanks

Hello Gurudath,

To manage to get the expansion file to work after trying many solutions without success, I ended up editing CCFileUtilsAndroid.cpp and changing the file access functions with more or less the ones that were in Cocos2d-X V2.X

Hi Jonathan,

Did you find solution? Is it working after editing CCFileUtilsAndroid.cpp file?

Yes it is working now after changing the CCFileUtilsAndroid.cpp file.

I have created .obb file using JOBB tool. How to access .obb file and how to load resources in cocos2dx version 3. Can you please guide me?

Thanks a lot

I used the zip command to create the obb (remember if you have media files in the obb they must not be compressed).

As I said in my first message I edited Cocos2dxHelper.java

Here is my modified CCFileUtilsAndroid:

CCFileUtilsAndroid.zip (5.2 KB)

Otherwise for music and sound files you can follow what was done in this thread:

1 Like

Hi,

Thank you for the solution.

Hi,

I tried with above solution. But am facing problem in loading image. I used zip command to create obb. Am not using any media file. Here is log that am getting. Am using ndk version 9d

12-09 16:39:34.550: D/CCFileUtilsAndroid.cpp(9304): asset is nullptr so not in apk
12-09 16:39:34.551: D/CCFileUtilsAndroid.cpp(9304): GETTING FILE RELATIVE DATA: HelloWorld.png
12-09 16:39:34.551: D/CCFileUtilsAndroid.cpp(9304): FileUtilsAndroid::getFileData
12-09 16:39:34.551: D/CCFileUtilsAndroid.cpp(9304): [AssetManager] … in APK assets/HelloWorld.png, found = false!
12-09 16:39:34.551: D/CCFileUtilsAndroid.cpp(9304): [s_pZipFile] … in OBB assets/HelloWorld.png, found = false!
12-09 16:39:34.551: D/CCFileUtilsAndroid.cpp(9304): GETTING FILE RELATIVE DATA: HelloWorld.png
12-09 16:39:34.551: D/CCFileUtilsAndroid.cpp(9304): Message Get data from file(HelloWorld.png) failed!

When i see log APK and OBB assets path are same. What may be problem?
Thanks

Hello,

I think the problem is from the obb, the obb should be the assets folder zipped.
Otherwise you can check that obb path is correct.

I have zipped the assets folder and renamed with .obb Am i doing anything wrong here. Is there any method to check if .obb file exist?
Thank you

Hi,

Thanks for the solution. It works for me.
There was problem with .obb file. When i use zip file it works fine.
What is method to create .obb file?

Regards
Gurudath

I just use the ‘zip’ command in the build process (in shell scripts).

Hi,

Okay. Thank you

Hi guys, sorry for lacking this feature.
I just create an issue here https://github.com/cocos2d/cocos2d-x/issues/9437, to support obb file officially in the engine.

Hi Jonathan,

Did you tried for Music? Is it working?
I made changes in music java file as per https://gist.github.com/stevetranby/3151c541a7ce17cbd9bc link. Am getting error while playing sound.

Thank you
Gurudath

Hello,

Yes I did the same changes for music as in the link (but I did not handle not using the expansion file so do not have the code where usingExpansionFiles is false).

Are your music file not compressed in the zip ?

Hi,

My music file is present in the compressed zip. Am getting file is present in OBB path as log. But am getting error.

AssetFileDescriptor assetFileDescritor = zip_resource_file.getAssetFileDescriptor( pPath );
soundID = mSoundPool.load( assetFileDescritor, 0 );

In above line error message is generated. Sounds are not playing.

Regards

The music and sound files need to be in the obb but they must not be compressed (just stored in the zip, no compression applied to them).

You can do it with this command which does not compress m4a and mp3 files ($file is the name of the obb) :
zip -r -n .m4a:.mp3 -q $file assets/*

Hello,

Thanks for the responce. I tried doing zip file using above command. But am getting same error. Where am doing wrong? Any idea?

Here is my error log:
2-10 18:27:11.189: D/CCFileUtilsAndroid.cpp(12547): [AssetManager] … in APK assets/ingameloop.mp3, found = false!
12-10 18:27:11.189: D/CCFileUtilsAndroid.cpp(12547): [s_pZipFile] … in OBB assets/ingameloop.mp3, found = true!
12-10 18:27:11.190: I/Cocos2dxSound(12547): Path: ingameloop.mp3
12-10 18:27:11.191: I/Cocos2dxSound(12547): Expansion file
12-10 18:27:11.192: I/Cocos2dxSound(12547): error files
12-10 18:27:11.194: E/Cocos2dxSound(12547): error: null
12-10 18:27:11.194: E/Cocos2dxSound(12547): java.lang.NullPointerException
12-10 18:27:11.194: E/Cocos2dxSound(12547): at org.cocos2dx.lib.Cocos2dxSound.createSoundIDFromAsset(Cocos2dxSound.java:346)
12-10 18:27:11.194: E/Cocos2dxSound(12547): at org.cocos2dx.lib.Cocos2dxSound.preloadEffect(Cocos2dxSound.java:156)
12-10 18:27:11.194: E/Cocos2dxSound(12547): at org.cocos2dx.lib.Cocos2dxSound.playEffect(Cocos2dxSound.java:196)
12-10 18:27:11.194: E/Cocos2dxSound(12547): at org.cocos2dx.lib.Cocos2dxHelper.playEffect(Cocos2dxHelper.java:236)
12-10 18:27:11.194: E/Cocos2dxSound(12547): at org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(Native Method)
12-10 18:27:11.194: E/Cocos2dxSound(12547): at org.cocos2dx.lib.Cocos2dxRenderer.onSurfaceCreated(Cocos2dxRenderer.java:73)
12-10 18:27:11.194: E/Cocos2dxSound(12547): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1501)
12-10 18:27:11.194: E/Cocos2dxSound(12547): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)