To automatically remove unnecessary resources of all types (strings, images, etc.), you must add a resource xml file (usually called res/raw/keep.xml
) and add to it:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:shrinkMode="strict"/>
However, the project build plugin will not be able to see resources accessed via reflection, so such resources should be labelled in tools:keep
with a comma, for example:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:shrinkMode="strict"
tools:keep="@string/tracer_app_token,@string/tracer_mapping_uuid"/>
The application will crash if it tries to access removed resources. If you find that a library is responsible, add the required resources to `tools:keep' as a workaround, and notify their creators to add this to the publishing library files.
Menu -> Analyze -> Run Inspection by Name -> Unused resources
– Nugent