Zipalign - Command not found - MAC terminal
Asked Answered
K

23

81

When I try to run Zipalign on an apk I get the error "Command not found"

I am not that familiar with using terminal commands on the MAC but I have navigated to the SDK/Tools folder and run the following command:

zipalign -v 4 Project1.apk Project1-aligned.apk

I get Command not found

I have tried placing the apks in the Tools folder and same result.

Can someone help me to understand where the apks should be located and where I should run zipalign from?

Thanks, I am very frustrated about this as it seems so simple.

Kamala answered 16/3, 2011 at 15:7 Comment(0)
T
89

You can find correct path with this command:

find ~/Library/Android/sdk/build-tools -name "zipalign"
Thanhthank answered 22/1, 2017 at 9:31 Comment(3)
You should receive a honor medal for this comment. You saved my life. Thanks, thanks and thanks again!!!Cafard
Yes, thank you that works. On my Mac the command yields: /Users/nicolasscozzaro/Library/Android/sdk/build-tools/28.0.2/zipalignEngle
Medal of Honor for you!Warmonger
C
78

Perhaps the current directory is not in your path?

Try adding "./" before your command so

./zipalign -v 4 Project1.apk Project1-aligned.apk
Coh answered 16/3, 2011 at 15:16 Comment(4)
I will try, thanks. I will also include the full path to the apk.Kamala
+1 for the correct answer, @Kamala please mark this as correct answer if this solved your problem!! it always encourage people who answer questions.Jannet
Worked as advertised for me.Crowell
Can a moderator marks this as the answer?Kerf
S
52

You will find the zipalign tool at /path/to/sdk/build-tools/<build-tools-version>/zipalign NOT in the tools folder anymore.

Seventeenth answered 20/10, 2014 at 5:56 Comment(0)
D
37
~/Library/Android/sdk/build-tools/xxxx/zipalign

Drag this to terminal or save this in your path. xxxx -> Version

Dearr answered 6/12, 2015 at 6:49 Comment(0)
L
27

Zipalign is a command that located at $ANDROID_HOME/build-tools/{android-version}/.

Hope it helped.

Langmuir answered 17/3, 2015 at 20:31 Comment(1)
ANDROID, not ADROD. But, thanks for your answer, it helped me.Volans
P
22

A simple one-liner:

  • This adds a line in your profile, to add the directory which contains the zipalign executable to your path
  • Then reloads the profile

echo "export PATH=\$PATH:~/Library/Android/sdk/build-tools/23.0.1/" >> ~/.bash_profile && . ~/.bash_profile

Make sure to replace 23.0.1 with your installed version

$ ls -l ~/Library/Android/sdk/build-tools/
total 0
drwxr-xr-x  23.0.1 <---

Now you should be able to use zipalign regardless of your current working dir

$ zipalign

Possing answered 28/10, 2016 at 12:36 Comment(3)
This is much more helpful.Podophyllin
drwxr-xr-x 23.0.1 <--- this line didn't give me the real version number, but after I fix it, it worked. Thank you.Lenssen
this is the real answer since by adding dir to PATH other tools in that dir like aapt can also be foundGriskin
P
15

on the mac with the zsh console, my solution was

command 1)

find ~/Library/Android/sdk/build-tools -name "zipalign"
----------------------------------------------------------
/Users/macOs/Library/Android/sdk/build-tools/28.0.3/zipalign
/Users/macOs/Library/Android/sdk/build-tools/26.0.2/zipalign
/Users/macOs/Library/Android/sdk/build-tools/25.0.2/zipalign
/Users/macOs/Library/Android/sdk/build-tools/27.0.3/zipalign

command 2)

echo "export PATH=\$PATH:~/Library/Android/sdk/build-tools/28.0.3/" >> ~/.bash_profile && . ~/.bash_profile

command 3)

ls -l ~/Library/Android/sdk/build-tools/

command 4)

zipalign -v 4 app-release-unsigned.apk nameApp.apk
Perfuse answered 13/3, 2019 at 5:48 Comment(0)
G
10

2hours resume for newbies (like me) :

If you type this command :

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

Witch gives you :

command not found: zipalign

It's maybe that the path is somewhere wrong. If you have this :

Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/bin/apt" (-1)

It confirms that its not really as it should be. So, to execute zipalign and finally publish your app, you have to go in the correct repository and execute commande.

1. Go to the correct repo to execute command :

The path is cd /Users/xxxyour_user_namexxx/Library/Android/sdk/build-tools/xxxxx/

cd /Users/greg/Library/Android/sdk/build-tools/28.0.3

2. Execute your zipalign command, don't forget to precise the path of apk file :

Obviously, chance "greg" and "myapp" with your user name & app name.

./zipalign -v 4 /Users/greg/Desktop/AppLocal/myapp/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk /Users/greg/Desktop/AppLocal/myapp/platforms/android/app/build/outputs/apk/release/app-release.apk

Hope it helps.

Gilson answered 14/3, 2019 at 10:31 Comment(0)
V
9

Search it and reference it... I have it here and reference it like this:

/Users/lioncio/Desktop/adt-bundle-mac-x86_64-20140702/sdk/build-tools/android-4.4W/zipalign bla bla bla (all the options of the command!)

And worked

Verdure answered 4/12, 2014 at 21:15 Comment(0)
K
8

Relax! , Just Use Locate Command in Terminal WHEREVER it is , it will come out

tom-MacBook-Air:kavform_app tom$ locate zipalign

/Users/tom/Software/android-sdk-macosx/build-tools/24.0.1/zipalign

/Users/tom/Software/android-sdk-macosx/docs/tools/help/zipalign.html  

In my case it was burried over here

/Users/tom/Software/android-sdk-macosx/build-tools/24.0.1/zipalign -v 4 /Users/tom/kavwork/kavform/kavform_app/platforms/android/build/outputs/apk/android-release-unsigned.apk BrideToBe.apk
Keeling answered 27/8, 2016 at 8:32 Comment(1)
I think this works just wanted to let you know you get this the first time it is run and have to wait a bit: "Please be aware that the database can take some time to generate; once the database has been created, this message will no longer appear."Gusset
T
5

add it to the path

on terminal

find path for zip align

find ~/Library/Android/sdk/build-tools -name "zipalign"

path: /Users/username/Library/Android/sdk/build-tools/26.0.1/zipalign

enter the path found in there

sudo nano /etc/paths

now on new terminal you can see zipalign reco

Throng answered 22/6, 2018 at 5:43 Comment(1)
The path you add to /etc/paths should be without /zipalignMelitta
C
3

Solution for Mac

This error basically means that the terminal wasn't able to find the zipalign file. So you can either type in the full path for your zipalign file with the command (located in your Android build-tools folder)

/Users/username/Library/Android/sdk/build-tools/26.0.1/zipalign -v 4 android-armv7-release-unsigned.apk helloWorld.apk;

If you do not know the location of the zipalign file, then just use this command

find ~/Library/Android/sdk/build-tools -name "zipalign"
Claudie answered 7/2, 2018 at 17:1 Comment(2)
is there a way to store the url that find returns? I'd like it to be dynamicIncurrent
Not any that I know of. Although, you can of course create a batch file that fetches the path, and then runs the command.Claudie
I
2

If you are working on Windows, change the command prompt to point to the folder containing the zipalign.exe and then run the command. Also, I have found that you are not using the complete command:

zipalign [-f] [-v] 4 Input.apk Output.apk
Isoline answered 17/3, 2011 at 6:11 Comment(0)
M
2

cd android-sdk/build-tools/22.0.0/ - change directory to android sdk folder, build tools and choose version (I used 22.0.0).

Then at the prompt type:

./zipalign -v 4 /MyApp/android-x86-release-signed.apk ~/MyApp/android-x86-release-signedandzipped.apk

That worked for me. I tried the other solutions above with no success. I just had to run the command withn the proper folder, but that wasn't explained clearly in other resources I checked.

Marijane answered 24/8, 2015 at 15:52 Comment(0)
P
2

Navigate to the path of the zip align and include that with the command

/Users/ignatiusandrew/Library/Android/sdk/build-tools/25.0.2/zipalign 4 android-release-unsigned.apk igi.apk

Perky answered 11/3, 2017 at 5:47 Comment(0)
K
1

Alternatively, if you do not want to add a specific build tools folder to the path, in case it changes in the future, you can use the first result of find command:

$(find ~/Library/Android/sdk/build-tools -name "zipalign" | head -n 1) <your-zipalign-parameters>

It might be especially useful in a CI pipeline.

Koniology answered 13/5, 2021 at 1:48 Comment(0)
O
0

for me this worked perfectly, I copied the zipalign file from the android path to the folder where I wanted to run command and then typed ./zipalign -v 4 android-release-unsigned.sdk nameofapp.apk

Note: It was on Mac

Oodles answered 29/2, 2016 at 16:33 Comment(0)
M
0
%ANDROID_HOME%\\build-tools\\25.0.2\\zipalign -v 4 .\\platforms\\android\\build\\outputs\\apk\\input.apk .\\path\\ output.apk
Monanthous answered 27/3, 2017 at 13:18 Comment(1)
Hi, welcome to Stack Overflow! Consider expanding this answer to explain why you believe the users are unable to make this command work and how executing it like this fixes the issue. Also it may be worth adding some text detailing how a user could add this to their PATH so that they can execute it like OP tried in the question. Those 2 edits would make this answer to a very old question much more useful for people looking for a good answer. Thank you!Convict
R
0

First, if your android home is set, then you can just cd $ANDROID_HOME and open . (This should be - /Users/username/Library/Android/, you can just cd to that path as well)

Next, navigate to "sdk/build-tools/25.0.3/" (version 25.0.3 in this case, yours may be a different version).

At your terminal (apk prompt), drag zipalign to the terminal and ...../zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk. Should work fine.

Hope it helps.

Republicanism answered 2/7, 2018 at 10:32 Comment(0)
E
0

Downloaded zipalign-file from github

zipalign exec copy and paste in your Project1-aligned.apk directory
./zipalign -v 4 Project1.apk Project1-aligned.apk
Eventual answered 9/11, 2018 at 1:41 Comment(0)
S
0

In my case I follow below answer

  1. Change directory

    /path/to/sdk/build-tools//zipalign

  2. Type

    ./zipalign instead zipalign

In short ./zipalign is solution for me.

Singles answered 10/1, 2019 at 5:59 Comment(0)
C
0

Solution for Jenkins

For Jenkins users using MacOS to build and sign mobile apps who are experiencing this error, the solution could be this:

At the stage where the signature is made:

withEnv(['PATH=/Users/jenkins/Library/Android/sdk/build-tools/29.0.3', 
'ANDROID_SDK_ROOT=/Users/jenkins/Library/Android/sdk', 
'JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home'])
Champ answered 7/2, 2023 at 7:23 Comment(0)
T
-1

I am using Windows with git bash/command promt

zipalign.exe needed to be configured in environment variables.

so include sdk folder 'build-tool' with android version folder you are using to build.

e.g. E:\android-sdk\build-tools\22.0.1

it should contain 'zipalign.exe'. now you can user

zipalign -v 4 Project1.apk Project1-aligned.apk

from any location using command line tools.

thumb up for me so i can help more developers.

Transudation answered 19/10, 2015 at 7:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.