9

I am trying to zipalign an "input.apk" file on an Ubuntu 14.04 LTS system using the command line as I do not have access to the source code just yet. If I'm not mistaken I should be able to do this with the following command

zipalign [-f] [-v] 4 intput.apk output.apk

but I am getting the following output

zipalign: command not found

I have made sure that the zipalign file is in my ...sdk/tools directory which I had to copy over from my ...build-tools/android-4.4W folder because it was originally missing. When I input this line as suggested in another question

./zipalign [-f] [-v] 4 intput.apk output.apk

I get the following output

Zip alignment utility
Copyright (C) 2009 The Android Open Source Project

Usage: zipalign [-f] [-v] <align> infile.zip outfile.zip
       zipalign -c [-v] <align> infile.zip

   <align>: alignment in bytes, e.g. '4' provides 32-bit alignment
   -c: check alignment only (does not modify file)
   -f: overwrite existing outfile.zip
   -v: verbose output

Does this mean that I need a .zip file instead of my .apk to zipalign?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
himahimahima
  • 397
  • 2
  • 4
  • 10

4 Answers4

19

When a usage message contains an argument in brackets, the brackets mean that that argument is optional and can be left out of the final command; the brackets are not themselves part of the command syntax.

In your case, correct usage might look like:

./zipalign -v 4 intput.apk output.apk 
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67
  • Many Thanks for your answer. It took me almost 1 hour to find the issue .. You made my day Thanks a lot – KK_07k11A0585 Sep 02 '14 at 06:22
  • Glad to help you @Jose – Haresh Chhelana Aug 04 '16 at 04:34
  • launching this command on a 64 bit machine can also not be enough giving "zipalign: error while loading shared libraries: libc++.so: cannot open shared object file: No such file or directory" as it happened to me... in this case I solved with liauau's answer from here: https://stackoverflow.com/questions/35336697/zipalign-error-while-loading-shared-libraries-libc-so-cannot-open-shared-ob – Antonino Jul 17 '17 at 07:14
11

In terminal,

cd /opt/android-sdk/build-tools/21.1.2

sudo ln -sf zipalign /usr/bin/

zipalign -v 4 platforms/android/ant-build/MainActivity-release-unsigned.apk platforms/android/ant-build/YOUR_APP.apk
gilcierweb
  • 2,598
  • 1
  • 16
  • 15
  • jenkins@ip-172-31-22-20:~/workspace/PP_androidBuild/PatientPortal$ zipalign -v 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 : alignment in bytes, e.g. '4' provides 32-bit alignment -c: check alignment only (does not modify file) -f: overwrite existing outfile.zip -v: verbose output – Ashish Karpe Sep 08 '17 at 13:29
3
  1. Open terminal (CTRL + t)
  2. cd YOUR_PATH/android-sdk-linux/build-tools/XX.X.X
  3. sudo cp zipalign /usr/bin/
  4. Open the folder where is located your apk in the terminal.
  5. Execute zipalign -v 4 YOUR_APK.apk YOUR_APK.apk
Ronald Araújo
  • 1,395
  • 4
  • 19
  • 30
0

I had the same issue. This is how i solved it, all you need is here.
1. Get zipalign path by getting sdk path on android studio. which is /Users/s****/Library/Android/sdk for me.
2. Paste the path on your terminal and cd to "build-tools/28.0.3/zipalign" now command will be
/Users/s****/Library/Android/sdk/build-tools/28.0.3/zipalign
3. zip the apk on the same command line by adding -v 4 app-release-unsigned.apk my.apkto the command, now command will be
/Users/s****/Library/Android/sdk/build-tools/28.0.3/zipalign -v 4 app-release-unsigned.apk my.apk
4. Done.

Ahmed Adewale
  • 2,943
  • 23
  • 19