As an example, in Cocos2dxSound.java, here are the modifications that need to be made.
createSoundIdFromAsset needs to be modified to read from a zip file. We can use the library provided by Google to help us with this ( included with the downloader library I believe ).
public int createSoundIdFromAsset(String path){
int soundId = INVALID_SOUND_ID;
try {
if (path.startsWith("/")){
soundId = mSoundPool.load(path, 0);
}
else {
AssetFileDescriptor assetFileDescritor = zip_resource_file_.getAssetFileDescriptor( path );
soundId = mSoundPool.load( assetFileDescritor, 0 );
}
} catch(Exception e){
soundId = INVALID_SOUND_ID;
Log.e(TAG, "error: " + e.getMessage(), e);
}
return soundId;
}
zip_resource_file_ is created by loading the zip file in the constructor:
SharedPreferences pref = context.getSharedPreferences( IdoniaDownloaderActivity.PREFS_NAME, 0 );
try {
zip_resource_file_ = APKExpansionSupport.getAPKExpansionZipFile(
context,
pref.getInt(
IdoniaDownloaderActivity.KEY_EXPANSION_FILE_VERSION,
IdoniaDownloaderActivity.DEBUG_APP_VERSION ),
0 );
} catch ( IOException e ) {
Log.e( "Cocos2dxMusic" , "Initializing zip_resource_file_", e );
}
I used SharedPreferences to help store and retrieve the location/name/version number of the expansion files.
I want to comment about the APK expansion packs though. After going through the hassle of uploading different expansion packs and application apk combinations for all the texture types, I don’t think I will continue to use this method in the future (depending on the game and how often it will be updated).
The reason for this is that when uploading to the developer console, the application version numbers are a bit confusing to deal with and if you make a mistake, you have to wait a LONG time to upload your application/expansion pack combo. Also, you have to organize the APKs so that the AndroidManifest.xml file properly define what GL extensions each apk/expansion pack support. Way too many ways to make a mistake.
Not to mention, the uploader on the developer console isn’t that great either because it provides minimal feed back during the upload process.
So depending on the size of the application and number of texture formats you support, it might be alright.
We decided not to for our game (~87 MB each with 4 texture types) and put the zip files on S3 and download them ourselves based on what the device supported. This allowed us to have a single application APK ( implieng also a single AndroidManifest.xml file ) that has the benefit of making the application update and versioning process much simpler.
The modifications mentioned above though stayed relevant, except for the location of the ZIP file we download ourselves.