netguy
netguy

Reputation: 641

Error while running zipalign

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.

Upvotes: 41

Views: 47926

Answers (19)

Randall Flagg
Randall Flagg

Reputation: 5098

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

Upvotes: 0

Dale C
Dale C

Reputation: 1

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

Upvotes: 0

Ahmed Adewale
Ahmed Adewale

Reputation: 3123

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.

Upvotes: -1

Karthikeyan VK
Karthikeyan VK

Reputation: 6006

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.

Upvotes: 0

FWhitaker
FWhitaker

Reputation: 31

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).

Upvotes: 0

Chun-Fu Chao
Chun-Fu Chao

Reputation: 466

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.

Upvotes: 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.

Upvotes: 6

J.G.Sebring
J.G.Sebring

Reputation: 5964

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)

Upvotes: 72

shamza
shamza

Reputation: 1

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

Upvotes: 0

Dawan
Dawan

Reputation: 166

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

Upvotes: 3

Boycott A.I.
Boycott A.I.

Reputation: 18871

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.

Upvotes: 0

Johny
Johny

Reputation: 119

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.

Upvotes: 0

Jet
Jet

Reputation: 1

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

Upvotes: 0

Mosquito
Mosquito

Reputation: 17

For mac

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

  1. open eclipse.ini
  2. add -Dfile.encoding=utf-8

Upvotes: -2

flypen
flypen

Reputation: 2585

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.

Upvotes: 0

JeffDenver
JeffDenver

Reputation: 71

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.

Upvotes: 7

Snicolas
Snicolas

Reputation: 38168

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

Upvotes: 1

Konrad
Konrad

Reputation: 1393

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

Upvotes: 1

netguy
netguy

Reputation: 641

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

Upvotes: 3

Related Questions