Apktool/brut.apktool
Igor Eisberg 4de92a23ae
refactor: ApkDecoder & ApkBuilder overhaul (#3699)
* refactor: ApkDecoder & ApkBuilder overhaul

A major rewrite of ApkDecoder and ApkBuilder classes to make them managable.
Removed many instances of redundancy and improved syntaxed and indentation.

Modifying the stock Apktool source to our needs have become too difficult,
so I'm pushing the general (not specific to our needs) changes upstream.

I'd change a lot more, but I wanted to make sure all tests pass as expected,
despite some of them being wierd, outdated or unnecessary.

This also fixes certain files in META-INF being lost during recompile
when the -c/--copy-original option isn't used.

This has been tweaked and tested for several days and I vouch for its stablity.

* style: fix more redundancy

* style: fix more redundancy

* tweak: consistent case-sensitivity for cmd and options

* refactor: tracking unknownFiles via apkInfo is redundant

1) We take advantage of the fact that doNotCompress already tracks uncompressed files,
   including those separated into "unknown".
   With this change the "unknownFiles" is simply ignored, so it's backward-compatible
   with existing decoded APK dirs.
   Tweaked a few tests to match the removal of "unknownFiles".

2) Passing doNotCompress to AAPT is redundant, Apktool extracts the temp APK packed by
   AAPT to build/apk and then repackages it anyway, so it serves no purpose.

* refactor: fix minSdkVersion from baksmali + clean up more redundancy

* Regression: minSdkVersion inferred from baksmali was not stored properly.

* The arsc extension can be generalized for simplicity as seen in AOSP source.
https://cs.android.com/android/platform/superproject/main/+/main:external/deqp/scripts/android/build_apk.py;l=644?q=apk%20pack&ss=android%2Fplatform%2Fsuperproject%2Fmain:external%2F
  Note:
    NO_COMPRESS_EXT_PATTERN only collapses paths to a common extension.
    It does NOT force these extensions to be always uncompressed.
    doNotCompress is the one determining files/extensions that should be uncompressed.
  (no funcionality was changed)

* resourcesAreCompressed in apkInfo is redundant. It was only used in invokeAapt,
  but not ApkBuilder. Its value is also never set by Apktool, only read.
  Like with doNotCompress, passing any kind of compression rules to AAPT is pointless,
  since we don't use the temp APK packed by AAPT directly - it's extracted and repacked
  by ApkBuilder, where doNotCompress already determines whether resources.arsc should
  or should not be compressed in the final APK.
  (no funcionality was changed)

* style: optional args come after required args

* style: optional args come after required args

* style: sdkInfo as a normal field for consistency

* style: some formatting tweaks
2024-10-03 06:52:59 -04:00
..
apktool-cli refactor: ApkDecoder & ApkBuilder overhaul (#3699) 2024-10-03 06:52:59 -04:00
apktool-lib refactor: ApkDecoder & ApkBuilder overhaul (#3699) 2024-10-03 06:52:59 -04:00