41

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.

netguy
  • 641
  • 1
  • 5
  • 11
  • 1
    Can you run the steps in http://d.android.com/guide/publishing/app-signing.html#releasemode and give the output of the first command that gives an error? – sargas Jan 03 '11 at 03:07

19 Answers19

72

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)
J.G.Sebring
  • 5,934
  • 1
  • 31
  • 42
  • 3
    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. – ubzack Nov 08 '12 at 19:36
  • 1
    Bad permissions on the directory can also cause it. – Brian White Jan 27 '15 at 13:38
  • 2
    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? – Sterling Mar 01 '15 at 22:45
  • 1
    @String: as for me my apk was opened in 7zip, so the file was locked. – user276648 Jun 01 '16 at 08:16
  • Thanks, I have updated answer to reflect your input. – J.G.Sebring Jun 03 '16 at 07:29
  • it needs a full path. `C:\blablabla` but why? it should know that apk is in outputs folder :/ – Prabs Mar 10 '17 at 06:20
7

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.

dldnh
  • 8,923
  • 3
  • 40
  • 52
JeffDenver
  • 71
  • 1
  • 1
6

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.

  • $ 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 Sep 08 '17 at 13:14
  • Installed 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] infile.zip outfile.zip zipalign -c [-v] infile.zip – Ashish Karpe Sep 08 '17 at 13:39
3

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

Dawan
  • 156
  • 4
3

If your pre-align APK is larger than 2GB, it will also cause this issue. Tested with build-tools 23.0.1 on Windows 10 machine.

Chun-Fu Chao
  • 466
  • 2
  • 10
  • I'm getting this issue, did you ever find a workaround? Thanks – Beloudest Sep 11 '17 at 16:50
  • @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. – Chun-Fu Chao Sep 11 '17 at 17:35
  • 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. :( – Beloudest Sep 11 '17 at 17:45
  • 1
    @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 – Chun-Fu Chao Sep 11 '17 at 17:49
  • Can you provide an answer that could fix this? – 0xabc Sep 06 '21 at 17:25
3

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

netguy
  • 641
  • 1
  • 5
  • 11
1

I got this error because I had no write access to the target directory. Changing the permission accordingly resolved the problem.

Konrad
  • 1,285
  • 21
  • 28
  • ls /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 Sep 08 '17 at 13:13
1

Sometimes a simple \ instead of a / in the destination file path can lead to this. Double check your multiplatform ant files!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Snicolas
  • 37,840
  • 15
  • 114
  • 173
0

If the destination file already exists and it is opened by another process, then you will see this error.

Solving method: Rename the destination file, or close the application that already opens the file.

flypen
  • 2,515
  • 4
  • 34
  • 51
0

Check the space available on the destination disk. I got the same error because my disk was full :-)

Jet
  • 1
0

In my case the problem was utf-8 named folder. I changed it into English and worked. I am using Windows 8 x64 Enterprise edition.

Johny
  • 119
  • 9
0

This issue occurred for me when I had my project's bin folder open in Windows Explorer.

I then tried to delete my old apk file (which the Export tool was unsuccessfully trying to overwrite), but I couldn't do that as I didn't have the necessary permission or because some other process had a lock on the file.

The solution was to restart my computer which released the lock on the apk file. Eclipse's Export tool then worked fine.

Update Could not delete the old apk file in Windows Explorer or in Command window (even when I opened it with Admin rights), but I could delete the apk when viewing it in my FileZilla FTP client application. Obviously, this is much more convenient than restarting the computer.

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
0

zipalign tool can't access to the source file, so you should verify path, file name, extension, permissions ...

shamza
  • 1
  • 1
0

Adding on my solution:

My problem was that my assets folder was too large, and must have been messing with the zipping somehow. I had to remove files in the asset folder (or add them to _pre_production).

FWhitaker
  • 31
  • 1
0

I had the same problem with my zipalign command. Output path was correct but the folders did not exist which was provided in the output path and so i created the folders manually and then it all worked fine.

Karthikeyan VK
  • 5,310
  • 3
  • 37
  • 50
0

I had to run cmd from project folder where the

C:\Users\User\Documents\phone app\7\proj7\platforms\android\build\outputs\apkandroid-release-unsigned.apk is located and enter this in cmd C:\Users\User\AppData\Local\Android\Sdk\build-tools\26.0.0\zipalign -v 4 android-release-unsigned.apk myApp-signed.apk

Angel F Syrus
  • 1,984
  • 8
  • 23
  • 43
Dale C
  • 1
0

What solved the issue for me, on windows, was to set the output folder to drive C:

Randall Flagg
  • 4,834
  • 9
  • 33
  • 45
-1

This is your mistake
You are trying to set or reference zipalign first and then run zipalign -v 4 app-release-unsigned.apk HelloWorld.apk
No, this is what you should do, set the zipalign reference and run the command at the same time
like this
/Users/s****/Library/Android/sdk/build-tools/28.0.3/zipalign -v 4 app-release-unsigned.apk MyApp.apk Your apk will build immediatelly.

Ahmed Adewale
  • 2,943
  • 23
  • 19
-2

For mac

Because the result of encoding does not match you must do this:

  1. open eclipse.ini
  2. add -Dfile.encoding=utf-8
mram888
  • 4,899
  • 5
  • 33
  • 59
Mosquito
  • 17
  • 1