Home » Android » Android – failed to open zip archive

Android – failed to open zip archive

Posted by: admin June 15, 2020 Leave a comment


I am downloading apk file from web and storing him into Context.getCacheDir(). I am downloading file by HttpURLConnection – I am not asking actually on the code (it is fully working), so I am not posting it here. I successfully initiate download. File is downloaded into cache and then is prompted installation – but system cannot open my APK and writes error of analysis.

Hence problem is as follows:

03-31 16:48:43.740: INFO/ActivityManager(59): Start proc com.android.packageinstaller for activity com.android.packageinstaller/.PackageInstallerActivity: pid=620 uid=10026 gids={}
03-31 16:48:44.749: WARN/zipro(620): Unable to open zip '/data/data/com.my.app/cache/myApp.apk': Permission denied
03-31 16:48:44.749: DEBUG/asset(620): failed to open Zip archive '/data/data/com.my.app/cache/myApp.apk'
03-31 16:48:44.930: WARN/PackageParser(620): Unable to read AndroidManifest.xml of /data/data/com.my.app/cache/myApp.apk
03-31 16:48:44.930: WARN/PackageParser(620): java.io.FileNotFoundException: AndroidManifest.xml

Problem is – I don’t have permission to access programaticaly /cache. Is there any way how to solve it? I don’t want to use external storage as a download directory (installation process works when I download file to external storage), cache is great because the file won’t be accessible for general user from file manager and that’s what I want. Thanks for your thoughts.

This problem has been for me unsolvable for over a month now…

Edit: Still no solution, I am trying to think that I found 1st thing, that is not possible with Android

Edit2: I must have been looking bad – my downloaded apk is present in cache… There is still no permission to allow install from that dir?

How to&Answers:

chmod 666 on the downloaded apk file before you install it in your code

more detail :

path = your_apk_file_path_in_cache_dir;

try {
    String command = "chmod " + permission + " " + path;
    Runtime runtime = Runtime.getRuntime();
} catch (IOException e) {


This is may help you:

FileOutputStream fOutputStream = context.openFileOutput(
    fileName, Context.MODE_WORLD_READABLE);


I see what’s happening..

The cache dir is a cache managed by Android, which means it can be cleaned as soon as the internal memory starts to run low.

AND if your application is taking too much space on a cache (what a APK is probably doing) when your application gets paused/stoped Android may clean your cache directory.

To test it this is the case, do everything as you did and when the installation process starts just open the DDMS and see if your file still in the cache.

If not, so android has cleaned the application’s cache because it’s not running anymore.

Try to user a different approach, instead of context.getCacheDir() try context.getFilesDir()