ngr resource
Prints the value of one or more resources of an apk, named by their identifier or by their full name. You use it
when you already know which resource you are looking for, for example @string/app_name, and you want its value.
To see which resources exist, use ngr info --resources. It reads the apk and writes nothing.
Usage
ngr resource [options] <apk> <resource>...
Inputs
| Input | What it is |
|---|---|
<apk> |
An apk file |
<resource> |
An identifier, in hexadecimal or decimal, or a full name such as @string/app_name. You can give several |
Options
| Option | What it does | Default |
|---|---|---|
--format <text|json|xml> |
Report format | text |
-v, --verbose |
Prints all the configurations of each resource found | |
-h, --help |
Shows the help |
What it writes
It writes no files. Each resource found goes to stdout, in the order you asked for it. By name:
ngr resource app.apk @string/app_name
resource="Example"
The same resource, by hexadecimal identifier and by decimal identifier:
ngr resource app.apk 0x7f120001
ngr resource app.apk 2131886081
Both give the same line. With several resources, each comes out on its own line:
ngr resource app.apk @string/app_name @bool/enabled 0x7f050000
resource="Example"
resource="true"
resource="false"
With -v each configuration of the resource comes out, with its qualifier in parentheses. The value without a
qualifier is the default configuration:
ngr resource -v app.apk @bool/enabled
resource [ configs = 3, id=0x7f050001, type=bool, name=enabled ]
() true
(-sw600dp) false
(-mcc310-mnc4) false
A resource that is a file gives its path inside the apk:
resource="res/layout/row.xml"
--format json and --format xml give the same structured result:
[
{
"resource":"true"
}
]
Examples
Read the application name:
ngr resource app.apk @string/app_name
See all the translations of a resource:
ngr resource -v app.apk @string/app_name
Ask for three resources at once, one by identifier:
ngr resource app.apk @string/greeting @drawable/ic_star 0x7f050001
Get the result as JSON:
ngr resource --format json app.apk @bool/enabled
Exit codes
| Code | When |
|---|---|
| 0 | The command ran. Also when a resource does not exist or is not valid, and with a protected apk or one without resources.arsc |
| 1 | The apk does not exist or cannot be read |
| 2 | The options are wrong: <apk> is missing or <resource> is missing |
Things to know
- A resource that does not exist is not an error.
resourcewarns on stderr, prints nothing to stdout and ends with 0. If you ask for several, it prints the ones it finds and warns about the rest:
WARN: resource not found: @string/nope
WARN: Can't find resource: @0x7f990000
WARN: Invalid resource: banana
The first warning is for a full name that is not in the table, the second for an identifier that is not there,
and the third for an argument that is neither an identifier nor a full name. A name without the @
(string/app_name) also comes out as Invalid resource. In a script, check whether stdout is empty, not the exit
code.
- An apk without
resources.arscprints nothing and ends with 0. - A protected apk gives no report.
resourcewritesWARN: PROTECTEDto stderr and ends with 0. - Resources that have several values come out with an empty value without
-v(resource=""): plurals, styles and arrays. Ask for-vto see their values.
See also
ngr info, to list the resources an apk has.ngr xml, to read a compiled xml, such as a layout.- “Inspecting an apk”.