7

I'm using aapt tool to read content of apk file with:

aapt d badging myapk.apk

But the output is too much. I just need the package name and version name. Any way to limit it?

Update: I got it to work on window cmd. Look like this:

aapt d badging myapk.apk | find "pack"
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
CodeBlue
  • 340
  • 2
  • 4
  • 9

5 Answers5

15

//try this

aapt d badging myapk.apk | grep 'pack'

its showing for me as

padmakumar@padmakumar-desktop:~$ aapt d badging ./Desktop/NhpAndroid_tablet_k4.apk  | grep 'pack'
package: name='com.ti.et.nspire.android' versionCode='1' versionName='1.0'
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130
  • hmmm... is it for linux? how can i get the same with cmd in window 7? – CodeBlue Mar 20 '12 at 11:35
  • nice answer, what if I want to show `package: name='com.**', versionCode='xx', versionName='xx.xx', ((sdkVersion:'xx', lable:'xxxx'))`? – Yousif Jul 11 '15 at 22:06
5

Here is a trick that work like charm for me. I'm using Backtrack 5 r2 ; GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

Assuming that "./aapt" executable is on the same directory of the Shell or Script. If not just add the path to executable or use export aapt="/path/to/aapt" and use the variable path.

out=$(./aapt dump badging GameCIH.apk | grep 'application-label:' | awk -F: 'match($0,":"){ print substr($0,RSTART+1)}' | tr -d "'" )

From aplication-label:'GameCIH' on apk

To only:

GameCIH

One last thing. If you want the package name or version name then do this:

out=$(./aapt dump badging GameCIH.apk | grep 'versionName=' | awk -F: 'match($0,"versionName="){ print substr($2,RSTART-8)}' | tr -d "'" )

This will return for example:

versionName=3.0.0

Just change the values versionName to whatever you need.

Change RSTART-8 for something like this: RSTART+4 and that will return:

3.0.0

I hope this could help!

Ismael Segui
  • 51
  • 1
  • 2
2
aapt d badging myapk.apk | grep package

for Windows, download UnxUtils to get grep and much more Linux command: http://unxutils.sourceforge.net/UnxUtils.zip

thucnguyen
  • 1,706
  • 15
  • 14
1

Here's the Bash function:

# Display package name and version of APK file(s)
apk(){
    (
        set -o pipefail

        for path in "$@"; do
            aapt dump badging "$path" \
            | awk $'
                BEGIN {
                    p=""
                    v=""
                }

                match($0, /^package: name=\'([^\']*)\'/, a) {
                    p=a[1]
                }

                match($0, /versionName=\'([^\']*)\'/, b) {
                    v=b[1]
                }

                END {
                    if (length(p) && length(v)) {
                        print p, v
                    }
                }'
        done
    )
}
Six
  • 5,122
  • 3
  • 29
  • 38
1
aapt d badging myapk.apk | awk '/package/ {print($2)}' | awk '{print(mstr[split($1, mstr, \"=\")])}' | tr -d \"'\"
Report Error
  • 414
  • 2
  • 5