Search code examples
androidregexgrepaapt

use egrep to get package name of android app


I am wanting to extract out the package name of my apk for a script.

I can list the package name with something like this

./aapt dump badging <apk.path> | grep package

The output looks like this

package: name='com.example.app' versionCode='' versionName='4.6.10' platformBuildVersionName='6.0-2166767'

so I want to run the aapt command and it only return com.example.app

I figured it would be something like, but still returns everything.

./aapt dump badging <apk.path> | egrep package:\ name='(.*?)'

Solution

  • Got it working by doing multiple greps and some regex. Below worked from me. Not sure if its the best way, but works.

    $ aapt dump badging <path.to.apk> | grep package | grep -Eo '[a-z]+\.\w+\.\w+' $ com.example.app