Skip to content

Conversation

@IgorEisberg
Copy link
Collaborator

@IgorEisberg IgorEisberg commented Jan 17, 2026

  • ApkBuilder: Refactored buildResources with well-documented order of operation.
  • ApkBuilder: Determine whether AndroidManifest.xml is raw using ResChunkHeader in buildResources.
  • ApkBuilder: Merged backupManifestFile into buildManifestOnly and buildResourcesFully where editing happens.
  • ApkBuilder: Made sure build closes the APK file even if an exception occurred to release file lock.
  • ApkBuilder, ApkDecoder: Normalized comments and logging.
  • AaptInvoker: Removed unused parameters (aapt2: -A and -R options are neither used nor needed).
  • AaptInvoker: Migrated getIncludeFiles from ApkBuilder.
  • BinaryXmlResourceParser: Initial usage of ResChunkPullParser (the rest is WIP for later).
  • Merged AbstractDirectory into Directory.
  • Cleaned and reorganized FileDirectory and ZipRODirectory.
  • Prefered FileDirectory/ZipRODirectory whenever possible, ExtFile is ambiguous and hides possible file lock.
  • XmlUtils: Renamed loadDocumentContent to parseDocument and used StringReader for performance.
  • Merged TestUtils into BaseTest.
  • Simplified throws in all tests to minimize imports (we don't care about specific exceptions there).
  • Removed all remaining unused imports in the source code.

The reasoning behind ExtFile is being reevaluated but kept unchanged for now.
Maintenance PR: No changes in usage or output.

Copy link

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 performs a comprehensive refactoring of the Apktool codebase focused on improving maintainability and code organization. The changes include merging AbstractDirectory into Directory, refactoring ApkBuilder and ApkDecoder with improved resource handling logic, migrating test utilities from TestUtils into BaseTest, and simplifying exception handling across all tests.

Changes:

  • Refactored directory hierarchy by merging AbstractDirectory into Directory base class
  • Improved ApkBuilder with clearer order of operations for resource building and proper file lock handling
  • Changed ApkDecoder.decode() return type from ApkInfo to void with separate getter method
  • Migrated getIncludeFiles() from ApkBuilder to AaptInvoker and removed unused aapt2 parameters
  • Merged TestUtils into BaseTest and simplified test exception declarations to throws Exception
  • Renamed XmlUtils.loadDocumentContent() to parseDocument() with performance improvement using StringReader

Reviewed changes

Copilot reviewed 68 out of 68 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
XmlUtils.java Renamed method and optimized XML parsing with StringReader
Directory.java, AbstractDirectory.java Merged abstract class into base class to simplify hierarchy
FileDirectory.java, ZipRODirectory.java Refactored to extend Directory directly with cleaned implementations
ExtFile.java Changed exception type from IOException to DirectoryException
ApkBuilder.java Major refactoring with improved resource building logic and file handling
ApkDecoder.java Changed API to void return with separate getter for ApkInfo
AaptInvoker.java Added getIncludeFiles() method and removed unused parameters
BaseTest.java Merged TestUtils functionality and simplified helper methods
Test files Simplified exception declarations and removed unused imports

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

@iBotPeaches
Copy link
Owner

I wish I properly organized all my samples that broke arsc parsing since trying to follow if these string pool changes are semantically the same.

@IgorEisberg
Copy link
Collaborator Author

I wish I properly organized all my samples that broke arsc parsing since trying to follow if these string pool changes are semantically the same.

I pretty much just merged ResStringPool.parse(BinaryDataInputStream) into doNext (the only place it's used) and verified the required main chunk RES_XML_TYPE instead of skipping it. The rest is the same until I wrap my head around what's going on there. There's effectively no difference, just more correct way of doing it.
I'm done for this PR. Tested on ROM build, diff is blank.

@IgorEisberg IgorEisberg merged commit 1dcf070 into main Jan 18, 2026
18 checks passed
@IgorEisberg IgorEisberg deleted the code-refactor branch January 18, 2026 02:38
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.

3 participants