Zulhilmi Zainudin
Zulhilmi Zainudin

Reputation: 9345

zipalign: command not found

I'm working on Ionic project now whereby I want to zipalign the android-release-unsigned.apk file. I followed this guide by Ionic.

When I run zipalign -v 4 /Users/zulhilmizainudin/Desktop/kl-parking/platforms/android/build/outputs/apk/android-release-unsigned.apk android-release.apk command, I get -bash: zipalign: command not found error.

This is where zipalign sit in my system:

/Users/zulhilmizainudin/Library/Android/sdk/build-tools/21.1.2

I tried to copy zipalign inside it and put it inside my Ionic project folder and run the zipalign command again. But still get the same command not found.

What should I do now?

Upvotes: 58

Views: 89196

Answers (10)

Bhavesh Jain
Bhavesh Jain

Reputation: 71

Windows

the right way is to add path to zipalign.exe as PATH environment variable.

Finding where zipalign.exe is located in your PC, in my case this was

C:\Users\username\AppData\Local\Android\sdk1\build-tools\29.0.2

Then add this location as one of the entries in your PATH environment variable.

MAC

To avoid specifying or navigating to your SDK/build-tools/* directories each time you intend to build a release version, you can simply add the path to your environment variable.

$ sudo nano ~/.bash_profile

copy and paste the below:

export PATH=${PATH}:/Library/Android/sdk/build-tools/21.1.2

You can then save and exit:

control + o // to save to file
control + x // to close the file
$ source ~/.bash_profile

You can then run your zipalign command from your project CLI directory.

Upvotes: 6

Jain Bhavesh
Jain Bhavesh

Reputation: 578

if you are making ionic release build then you can make build.json file on your app's root folder with these information given below

{
"android": {
   "release": {
   "keystore": "Your keystore",
   "storePassword": "password",
   "alias": "alias name",
   "password" : "password",
   "keystoreType": ""
    }
}  }

make sure that you can place your keystore on your app's root folder or provide full path of your keystore at keystore object

now just you can run this command as below

ionic cordova build android --release

this command automatically find your build.json and make signed release build.

Upvotes: 5

kat
kat

Reputation: 5950

I solved this problem by making the zipalign path an environment variable:

export ZIPALIGN_PATH=~/Library/Android/sdk/build-tools/30.0.3/zipalign

Then I replaced zipalign with $ZIPALIGN_PATH in the script I was trying to run

Upvotes: 2

Punnerud
Punnerud

Reputation: 8021

This worked for me on Mac. Install and run Android Studio (important to start it one time). Then find zipalign:

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

Upvotes: 5

Shoniisra
Shoniisra

Reputation: 781

Solved!

I copied zipalign file as Michael Said ( from my Library/Android/SDK/build-tools/28.0.3 into my Ionic project folder)

BUT when I run

./zipalign -v 4 app-release-unsigned.apk botellamovil.apk

I got

./zipalign: ERROR while loading shared libraries: libc++.so: cannot open shared object file: **No such file or directory**

So, I also copied lib & lib64 files, and then it Works!!

I hope it will be helpful :) (and sorry for my English)

Upvotes: 3

Mina Farid
Mina Farid

Reputation: 5887

You should do (align, sign, and verify)for APK. In mac, you should do the following steps:

A - Aligning APK:

1- you should locate zipalign your build tools inside android SDK:

/Users/mina/Downloads/sdk/build-tools/29.0.3/zipalign

2- you should locate your unsigned apk:

 /Users/mina/Desktop/apks/app_unsigned.apk

3- you should run command contains:

zipalign_path + -v -p 4 + unsigned_apk_path + output_aligned_apk_name

/Users/mina/Downloads/sdk/build-tools/29.0.3/zipalign -v -p 4 
/Users/mina/Desktop/apks/app-unsigned.apk app_aligned.apk

4- output is Verification successful

B - Signing APK:

1- you should locate apksigner your build tools inside android SDK:

/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner

2- you should locate your release-Keystore in your pc:

/Users/mina/Desktop/keys/release-Keystore.jks

3- you should run command contains:

apksigner_path + sign --ks + release-Keystore_path + --out + output_signed_apk_name + from_aligned_apk_name

/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner sign --ks 
/Users/mina/Desktop/keys/release-keystore.jks                                                    
 --out app_signed.apk app_aligned.apk

4- enter your key store password

C- Verifying APK:

1- run the following command : apksigner_path + verify + app_signed.apk

/Users/mina/Downloads/sdk/build-tools/29.0.3/apksigner verify 
app_signed.apk

Notes: you may find some warnings:

 WARNING: META-INF/.... 

Here is some description about that:

Apk Metainfo Warning

In practice, these files are not important, they're mostly versions of libraries you depend on, so even if someone modified those, it wouldn't have any impact on your app. That's why it's only a warning: those files in your APK can be modified by someone else while still pretending that the APK is signed by you, but those files don't really matter.

D- find your signed APK:

/Users/mina/app_signed.apk

Upvotes: 3

Laurent
Laurent

Reputation: 29

I'm running into several problems since I installed Kali from the USB live installer. I found out that I needed to add this into my sources.list file in /etc/apt folder. Just replace the content of sources.list with:

deb http://http.kali.org/kali kali-rolling main contrib non-free
deb-src http://http.kali.org/kali kali-rolling main contrib non-free
deb http://old.kali.org/kali sana main non-free contrib
deb http://ftp.de.debian.org/debian wheezy main

Upvotes: 1

Abayomi Israel
Abayomi Israel

Reputation: 629

To avoid specifying or navigating to your sdk/build-tools/* directories each time you intend to build release version, you can simply add the path to your environment variable.

$ sudo nano ~/.bash_profile

copy and paste the below:

export PATH=${PATH}:/Library/Android/sdk/build-tools/21.1.2

You can then save and exit:

control + o // to save to file
control + x // to close the file
$ source ~/.bash_profile

You can then run your zipalign command from your project CLI directory.

Upvotes: 22

Marinski
Marinski

Reputation: 431

If you're using Windows, the right way is to add path to zipalign.exe as PATH environment variable.

  1. Finding where zipalign.exe is located in your PC, in my case this was

C:\Users\random-username\AppData\Local\Android\sdk1\build-tools\24.0.1

  1. Then add this location as one of the entries in your PATH environment variable.

Upvotes: 31

Zulhilmi Zainudin
Zulhilmi Zainudin

Reputation: 9345

Solved!

  1. I copied zipalign file from my Library/Android/sdk/build-tools/21.1.2 into my Ionic project folder

  2. I add ./ in front of the zipalign command like this - ./zipalign -v 4 /Users/zulhilmizainudin/Desktop/kl-parking/platforms/android/build/outputs/apk/android-release-unsigned.apk android-release.apk

  3. Done. Now I get android-release.apk inside my Ionic project folder.

Thanks to Michael for the solution!

Upvotes: 98

Related Questions