Skip to content

fix: avoid assumptions about res dir#4067

Merged
IgorEisberg merged 3 commits into
mainfrom
fix-res-dir
Jan 14, 2026
Merged

fix: avoid assumptions about res dir#4067
IgorEisberg merged 3 commits into
mainfrom
fix-res-dir

Conversation

@IgorEisberg
Copy link
Copy Markdown
Collaborator

Fixes: #3507
Fixes: #3615
Fixes: #3810

Background:
When building, res folder is the only recognized folder for resources. That is unambiguous.
That isn't true when decoding. While assets and lib are reserved names by the system, there is no requirement that file resources are all under res in an APK - they can be anywhere (even in assets and lib) and obfuscators exploit it.
The only arbiter of what is a file resource and what isn't is resources.arsc.
We already handle filtering file resources under assets and lib (only possible by an obfuscator) when decoding with resources, but we were still assuming that res/R/r were guaranteed to contain file resources only. This caused misc files in res folder to be dropped when they appeared in JARs like framework.jar, which doesn't have a resources.arsc, and thus no file resources either.

Solution:
Make no assumptions about the location of file resources at all. Paths of file resources can only be determined when decoding with resources by trusting resources.arsc. Anything that wasn't referenced in resources.arsc is inherently unknown and goes to the unknown folder to be repacked as-is.

Note:
When decoding without resources, resources.arsc is not parsed and no file resource paths are established, thus all "potential resources folders" (res, R, r or whatever) end up in unknown and will be repacked as-is.
The advantage: We no longer need to explicitly hardcode "potential resources folders" in Apktool. We trust resources.arsc only.

Extra:
Tweaked the appropriate test for this change.
Tweaked Directory to use varargs instead of explicit array for more utility.
Cleaned an unused import and some old code that isn't used anymore.

Tested on a full ROM rebuild. No diffs except framework.jar that is now decoded properly.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issues where Apktool made incorrect assumptions about resource directory locations during decoding. Previously, directories named res, R, or r were assumed to contain only file resources, which caused problems when these directories appeared in JARs without a resources.arsc file (like framework.jar).

Changes:

  • Removed hardcoded assumptions about resource directory names (RESOURCES_DIRNAMES)
  • Modified behavior to trust only resources.arsc as the source of truth for file resources
  • Refactored Directory interface to use varargs for improved utility
  • Updated test expectations to reflect new behavior where unrecognized resource directories go to unknown folder

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
brut.j.dir/src/main/java/brut/directory/Directory.java Changed method signatures to use varargs instead of explicit arrays
brut.j.dir/src/main/java/brut/directory/AbstractDirectory.java Implemented varargs methods by reordering single and multi-argument implementations
brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java Updated test to expect r folder contents in unknown directory when decoding without resources
brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/data/StyledString.java Removed unused import
brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java Simplified logic by removing special-case handling and always mapping input to output filenames
brut.apktool/apktool-lib/src/main/java/brut/androlib/meta/ApkInfo.java Removed RESOURCES_DIRNAMES constant and its usage in STANDARD_FILENAMES_PATTERN
brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java Removed copying of RESOURCES_DIRNAMES directories in raw resource mode
brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkBuilder.java Refactored build logic with improved file freshness checking and consolidated resource building methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread brut.j.dir/src/main/java/brut/directory/AbstractDirectory.java
Comment thread brut.j.dir/src/main/java/brut/directory/AbstractDirectory.java
Comment thread brut.j.dir/src/main/java/brut/directory/AbstractDirectory.java
Comment thread brut.j.dir/src/main/java/brut/directory/AbstractDirectory.java
@IgorEisberg IgorEisberg merged commit 7169d20 into main Jan 14, 2026
18 checks passed
@IgorEisberg IgorEisberg deleted the fix-res-dir branch January 14, 2026 12:53
iBotPeaches added a commit to iBotPeaches/apktool.org that referenced this pull request Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] recompiled framework.jar is not correct [BUG] Ignores res folder of framework.jar [BUG] Recompiling system jars produces strange jars

3 participants