Error while running zipalign
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
netguy
Updated on July 09, 2022Comments
-
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 over 11 yearsGreat 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 over 11 yearsyou try? I used this method successfully addressed
-
Brian White over 9 yearsBad permissions on the directory can also cause it.
-
Sterling about 9 yearsBuilding 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 almost 8 years@String: as for me my apk was opened in 7zip, so the file was locked.
-
J.G.Sebring almost 8 yearsThanks, I have updated answer to reflect your input.
-
Kiara Grouwstra over 7 yearsSo on Windows use backslashes :), thanks, did it for me.
-
Prabs about 7 yearsit needs a full path.
C:\blablabla
but why? it should know that apk is in outputs folder :/ -
Ashish Karpe over 6 yearsls /var/lib/jenkins/workspace/PP_androidBuild/PatientPortal/platforms/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/platforms/android/build/outputs/apk/android-debug.apk
-
Ashish Karpe over 6 years$ zipalign zipalign: command not found jenkins@ip-172-31-22-20:~/workspace/PP_androidBuild/PatientPortal$ sudo apt-get install zipalign Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package zipalign
-
Ashish Karpe over 6 yearsInstalled Zipalign now getting error : jenkins@ip-172-31-22-20:~/workspace/PP_androidBuild/PatientPortal$ /opt/android-sdk-linux/build-tools/23.0.1/zipalign -f -p 4 /var/lib/jenkins/workspace/PP_androidBuild/PatientPortal/platforms/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 over 6 yearsI'm getting this issue, did you ever find a workaround? Thanks
-
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 over 6 yearsThanks 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 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 over 2 yearsCan you provide an answer that could fix this?