Download zip file and extract in android and ios

Download zip file and extract in android and ios

Hello, I am developing self-update system for native environments (android and ios). I tried some node library for downloading but no luck. Is there a way to download zip file and extract to resources folder ?

1 Like

@nshermione Hi there ! Have you found any solution for this ?


I’ve had to download and extract a zip on cocos2dx and I did the with the following:

For downloading use the code explained here: How to download zip file from url and save it on writable directory with cocos2d-x v3.11

For extraction you will need to use some libraries for native code:

iOS - objective C (
- (void)unzip:(NSObject *)parametersObject {

    NSString *zipPath = @((FileUtils::getInstance()->getWritablePath() + "").c_str());
    NSString *destPath = @((FileUtils::getInstance()->getWritablePath()).c_str());
    // Unzip on a new thread
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [SSZipArchive unzipFileAtPath:zipPath toDestination:destPath overwrite:false password:nil error:nil];
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"File extracted correctly");
            // Delete de .zip file
            [[NSFileManager defaultManager] removeItemAtPath: zipPath error: nil];

Android - Java (

private void unZip() {
Log.d("", “Start unzip, zip located at: " + Cocos2dxHelper.getCocos2dxWritablePath() + “/”);
String targetPath = Cocos2dxHelper.getCocos2dxWritablePath() + “/”;
String destinationPath = Cocos2dxHelper.getCocos2dxWritablePath();
ZipUtil.unpack(new File(targetPath), new File(destinationPath));
Log.d(”", “Unzipped!”);
new File(targetPath).delete();