-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
refactor: ApkDecoder & ApkBuilder overhaul #3699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
Left me some reviewing to do. |
Couple skim comments
|
|
By the way, this:
There's no reason to use "equalsIgnoreCase" here either because the options are case-sensitive anyway. |
Here's my take - let's keep the "equals" checks and if those broken APKs appear we can revert what's relevant. |
I have a question for you too: Do we really need
However, with my changes, everything in META-INF (except for |
In my opinion there is a clear distinction in Apktool of unknown files (we know nothing) and known Android files of the ones we process the ones we know are supposed to be there and passed along (libs, lib, kotlin, meta-inf, etc) |
Hmm well then there are more folders that match the description, like |
Perhaps what you are leading to is the idea of splitting unknown and files we track (originals, etc) is moot. I could see that aspect as tracking those individually makes no sense when they are both just packed into the application. The split stems from some files having to be tacked onto the aapt/aapt2 process while others are just "zipped" in post build. |
Yes, there is no limit to how many "known" but non-AAPT related folders or files can appear in the future but being "known" means nothing in terms of editing the app, e.g. EDIT: With that said, using the name |
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.
For now, I didn't touch
Should be as simple as:
And it works great. The rest is later repacked to the final APK. That's what I'm using in our custom Apktool, it simply avoids the whole "what is known?" question. |
Only on my phone right now, but a bit worried with all the compress changes. We have years of bugs about files losing intended compression, older apks compressing arsc files, newer apks not doing so for random access. Those changes will take some reviewing. |
There is no compression change for resources.arsc. It's listed in |
* 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)
Thanks! Please support me with any regressions we may see. |
A major rewrite of ApkDecoder and ApkBuilder classes to make them manageable. Removed many instances of redundancy and improved syntax 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 weird, outdated or unnecessary.
This also fixes certain files in META-INF being lost during recompile when the -c/--copy-original option isn't used.
Also, fixes the expected behavior for -j/--jobs option, e.g. for "-j 1" it's expected to do everything on the main thread, so for j > 1 it's actually j-1 for smali/baksmali, and the last one is for the main thread (for aapt).
Also, when smali fails (e.g. due to method limit exceeded), it'll now correctly show which of the smali dirs failed to smali.
This has been tweaked and tested for several days and I vouch for its stability.