Skip to main content

Frameworks

As you probably know, Android apps utilize code and resources that are found on the Android OS itself. These are known as framework resources and Apktool relies on these to properly decode and build apks.

Every Apktool release contains internally the most up-to-date AOSP framework at the time of the release. This allows you to decode and build most apks without a problem. However, manufacturers add their own framework files in addition to the regular AOSP ones. To use apktool against these manufacturer apks you must first install the manufacturer framework files.

Example: Lets say you want to decode HtcContacts.apk from an HTC device. If you try you will get an error message.

$ apktool d HtcContacts.apk
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: 1.apk
W: Could not decode attr value, using undecoded value instead: ns=android, name=drawable
W: Could not decode attr value, using undecoded value instead: ns=android, name=icon
Can't find framework resources for package of id: 2. You must install proper framework files, see project website for more info.

We must get HTC framework resources before decoding this apk. We pull com.htc.resources.apk from our device and install it

$ apktool if com.htc.resources.apk
I: Framework installed to: 2.apk

Now we will try this decode again.

$ apktool d HtcContacts.apk
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: /home/brutall/apktool/framework/1.apk
I: Loading resource table from file: /home/brutall/apktool/framework/2.apk
I: Copying assets and libs...

As you can see, Apktool leveraged both 1.apk and 2.apk framework files in order to properly decode this application.

Finding Frameworks

For the most part, any apk in /system/framework on a device will be a framework file. On some devices, they might reside in /data/system-framework and even cleverly hidden in /system/app or /system/priv-app. They are usually named with the naming of "resources", "res", or "framework".

info

HTC has a framework called com.htc.resources.apk, LG has one called lge-res.apk

After you find a framework file, you could pull it via adb pull /path/to/file or use a file manager application. After you have the file locally, pay attention to how Apktool installs it. The number that the framework is named during install corresponds to the pkgId of the application. These values should range from 1 to 30. Any APK that installs itself as 127 is 0x7F, which is an internal pkgId.

Internal Frameworks

Apktool comes with an internal framework like mentioned above. This file is copied to your local machine during the execution.

warning

Apktool has no knowledge of what version of framework resides there. It will assume its up to date, so delete the file during Apktool upgrades

Managing framework files

Frameworks are stored in different places depending on the OS in question.

  • Linux - $HOME/.local/share/apktool
  • Windows - %UserProfile%\AppData\Local\apktool
  • Mac - $HOME/Library/apktool

If these directories are not available, it will default to java.io.tmpdir which is usually /tmp. This is a volatile directory, so it would make sense to take advantage of the parameter --frame-path to select an alternative folder for framework files.

Since these locations are sometimes hidden directories, managing these frameworks becomes a challenge. A simple helper function (added in v2.2.1) allows you to run apktool empty-framework-dir to empty out frameworks.

info

ktool has no control over the frameworks once installed, but you are free to manage these files on your own.

Tagging framework files

Frameworks are stored in the naming convention of: <id>-<tag>.apk. They are identified by pkgId and optionally custom tag. Usually tagging frameworks isn't necessary, but if you work on apps from many different devices and they have incompatible frameworks, you will need some way to easily switch between them.

You could tag frameworks by:

$ apktool if com.htc.resources.apk -t hero
I: Framework installed to: /home/brutall/apktool/framework/2-hero.apk
$ apktool if com.htc.resources.apk -t desire
I: Framework installed to: /home/brutall/apktool/framework/2-desire.apk

Then:

$ apktool d HtcContacts.apk -t hero
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: /home/brutall/apktool/framework/1.apk
I: Loading resource table from file: /home/brutall/apktool/framework/2-hero.apk
I: Copying assets and libs...
$ apktool d HtcContacts.apk -t desire
I: Loading resource table...
I: Decoding resources...
I: Loading resource table from file: /home/brutall/apktool/framework/1.apk
I: Loading resource table from file: /home/brutall/apktool/framework/2-desire.apk
I: Copying assets and libs...

You don't have to select a tag when building apk - apktool automatically uses the same tag, as when decoding.