Error while running zipalign

41,068

Solution 1

I was getting the same error message. Drove me crazy until i found that my destination path was invalid.

Zipalign will give you that error even if the apk is perfectly valid, but

  • the path to the apk is invalid
  • the destination is invalid or does not exists
  • the permissions are invalid (apk is locked by other program)

Solution 2

I had this same problem and yes, it was because the tool could not recognize the path. I was using the wrong slash because I got bad advice from a developer blog.

Sample line command if the file "origin.apk" is in a folder called “storage” in the C directory:

zipalign -f -v 4 “c:\storage\origin.apk” “c:\storage\done.apk”

Make sure you use the slash above the enter key...a lot of the "examples" I have seen use the one by the shift key and that will not work. This will take the apk called “origin.apk” and zipalign it and then save it to the same directory as the file “done.apk”.

Maybe this is just on Vista, I dont know. I am using Windows Vista 32-bit.

Solution 3

In my case, I ran the command from the directory where the unsigned apk was and it ran perfectly.

cd /platforms/android/build/outputs/apk
zipalign -v 4 android-release-unsigned.apk signed.apk 

This way, I didn't need to worry about specifying the directory.

ps: I did this on ubuntu.

Solution 4

I removed the apk file in the Deploy directory and the export worked fine then.

Solution 5

I had to provide the full path for the unsigned APK file: platforms/android/build/outputs/apk/android-release-output.apk

Share:
41,068
netguy
Author by

netguy

Updated on July 09, 2022

Comments

  • netguy
    netguy almost 2 years

    I got this error when trying to export a signed apk in Eclipse

    Error while running zipalign: Unable to open as zip archive

    I have run the Help->Check for Updates to make sure the latest update is installed and SDK tools also up to date.

  • ubzack
    ubzack over 11 years
    Great answer. This was the case with my problem, specifically it was because the destination path did not exist. So, NOTICE: zipalign will not create directories for you.
  • Mosquito
    Mosquito over 11 years
    you try? I used this method successfully addressed
  • Brian White
    Brian White over 9 years
    Bad permissions on the directory can also cause it.
  • Sterling
    Sterling about 9 years
    Building on @BrianWhite's answer, I had this when the previous APK was locked by another program - essentially a permissions problem, but on the destination file rather than the directory. Why can't Gradle give you a reasonable error message, such as "Unable to create APK", rather than this cryptic BS?
  • user276648
    user276648 almost 8 years
    @String: as for me my apk was opened in 7zip, so the file was locked.
  • J.G.Sebring
    J.G.Sebring almost 8 years
    Thanks, I have updated answer to reflect your input.
  • Kiara Grouwstra
    Kiara Grouwstra over 7 years
    So on Windows use backslashes :), thanks, did it for me.
  • Prabs
    Prabs about 7 years
    it needs a full path. C:\blablabla but why? it should know that apk is in outputs folder :/
  • Ashish Karpe
    Ashish Karpe over 6 years
    ls /var/lib/jenkins/workspace/PP_androidBuild/PatientPortal/pla‌​tforms/android/build‌​/outputs/apk/android‌​-debug.apk -lthr -rw-r--r-- 1 jenkins jenkins 5.9M Sep 8 13:10 /var/lib/jenkins/workspace/PP_androidBuild/PatientPortal/pla‌​tforms/android/build‌​/outputs/apk/android‌​-debug.apk
  • Ashish Karpe
    Ashish Karpe over 6 years
    $ zipalign zipalign: command not found jenkins@ip-172-31-22-20:~/workspace/PP_androidBuild/PatientP‌​ortal$ sudo apt-get install zipalign Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package zipalign
  • Ashish Karpe
    Ashish Karpe over 6 years
    Installed Zipalign now getting error : jenkins@ip-172-31-22-20:~/workspace/PP_androidBuild/PatientP‌​ortal$ /opt/android-sdk-linux/build-tools/23.0.1/zipalign -f -p 4 /var/lib/jenkins/workspace/PP_androidBuild/PatientPortal/pla‌​tforms/android/build‌​/outputs/apk/android‌​-debug.apk Zip alignment utility Copyright (C) 2009 The Android Open Source Project Usage: zipalign [-f] [-p] [-v] [-z] <align> infile.zip outfile.zip zipalign -c [-v] <align> infile.zip
  • Beloudest
    Beloudest over 6 years
    I'm getting this issue, did you ever find a workaround? Thanks
  • Chun-Fu Chao
    Chun-Fu Chao over 6 years
    @Beloudest Sorry, I cannot recall what happened then. I checked my notes and social media but there is nothing related to it. I guess I always build with OBB after that so I didn't make a special note. Sorry it's not very helpful.
  • Beloudest
    Beloudest over 6 years
    Thanks for the reply, its due to the expansion file size for Android APK's, which is 2GB. 2GB for the main and 2GB for the patch. It sucks for me and my client trying to make an easy install file for users in the deserts of Africa. :(
  • Chun-Fu Chao
    Chun-Fu Chao over 6 years
    @Beloudest Pushing OBB over adb push is a bit tricky for non developer, I used to write batch file that install apk then push OBB for our QA
  • 0xabc
    0xabc over 2 years
    Can you provide an answer that could fix this?