5

Specifications:

  • Android Studio Version: Android Bumblebee
  • Android Build SDK Build-Tool : 30.0.3
  • Android SDK Command-line Tools: 7.0

I am trying to sign apk using apksigner. I am using this command in my Android Studio Terminal

apksigner sign --ks release.jks app.apk

I am following the official documentation but I am getting this error

bash: apksigner: command not found

When I dig further I found that Android/sdk/cmdline-tools/7.0/bin does not have apksigner it has following command line tools

enter image description here

What am I missing here? I tried downloading cmdline-tools/6.0 and 3.0 but I don't see apksigner there.

Rohit Singh
  • 16,950
  • 7
  • 90
  • 88

2 Answers2

5

You need to add a path variable in bash profile

I have written this answer based on the discussion with Commansware and Pierre on Commansware answer.

Let's discuss these questions to fix the command not found the issue on Android Studio.

Where is apksigner?

You can find apksigner at Android/sdk/build-tools/30.0.3

How to use apksigner using terminal?

  1. with absolute path (painful way)

    $ ~/Library/Android/sdk/build-tools/30.0.3/apksigner verify ~/Desktop/app-release.apk

  2. with $path variable (the smart way)

    $ apksigner verify ~/Desktop/app-release.apk

For this, you need to set a path variable in your bash profile

How to set path variable?

Add this to your bash profile

export PATH="$PATH:$HOME/Library/Android/sdk/build-tools/30.0.3"

Now you should be able to run $ apksigner verify ~/Desktop/app-release.apk anywhere even inside Android Studio terminal.

Still can't run the command on Android Studio?

In my case, I was not able to run apksigner command even after setting the path variable. So wrote export PATH="$PATH:$HOME/Library/Android/sdk/build-tools/30.0.3" on Android Studio terminal. And it worked!

Extra discussion

apksigner is part of Android Studio CLI tools. But I found that other Android Studio CLI tools (d8, avdmanager, aapt etc) command work by default except for apksigner. I don't know if it was just me or if it happens with others too.

Rohit Singh
  • 16,950
  • 7
  • 90
  • 88
2

apksigner is part of the SDK build tools. So, you should find it in $ANDROID_SDK/build-tools/30.0.3/, where $ANDROID_SDK is wherever you have your Android SDK installed.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    I did find it under $ANDROID_SDK/build-tools/30.0.3/ but why apksigner gives command not found but other other command-line-tools work for eg: sdkmanager , avdmanager works just fine – Rohit Singh Aug 28 '22 at 00:29
  • Is it possible to run apksigner command from Android Studio terminal ? – Rohit Singh Aug 28 '22 at 00:30
  • 1
    It is, but you need the build_tools/30.0.3 directory in your $PATH environment variable. – Pierre Aug 28 '22 at 05:43
  • Or, specify the fully-qualified path to the program when you run it. In other words, this works no differently than with any other program. – CommonsWare Aug 28 '22 at 10:45
  • ....../Android/sdk/build-tools/30.0.3/apksigner: line 31: dirname: command not found after setting export PATH="$HOME/Library/Android/sdk/build-tools/30.0.3/lib" @Pierre – Rohit Singh Aug 29 '22 at 17:13
  • @RohitSingh: I am unclear why you put `lib/` at the end of that. At least for me, on macOS and Linux, `apksigner` is directly in `30.0.3`. – CommonsWare Aug 29 '22 at 17:24
  • I added an answer based on the discussion here with @CommonsWare and Pirre . Thanks – Rohit Singh Sep 01 '22 at 18:56