-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
refactor: convert meta classes to pojo #3868
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
Wanted to make that change back when I converted Config class to POJO, finishing the job now. This will guarantee safe access to all meta classes (moved from brut.androlib.apk to brut.androlib.meta to make more sense). All non-primitive fields are guaranteed to never be null. Outputs clean apktool.yml without useless fields that don't affect the rebuild procedure. Still backwards compatible, just cleaner output, especially for JARs. Cleaned some logic in a few classes, especially related to updateApkInfo and loading of libraries/frameworks. It was a mess that was difficult to make sense of. Test issue1235 removed, it's a aapt1 duplicate of aapt2's issue2328/debuggable-false. Misc style tweaks for consistency. Tested on a ROM decompile/recompile, no regression detected.
Did the checker die or something? |
Hmm that is odd. Actions not showing the commit. |
There, it's back from slumber. |
There was a problem hiding this 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 refactors several classes to convert meta classes to POJO, streamlining access and cleaning up output while ensuring backwards compatibility. Key changes include package renaming (from brut.androlib.apk to brut.androlib.meta), updates to manifest and resource decoding logic, and various style and naming improvements across classes such as ApkInfo, VersionInfo, and UsesFramework.
Reviewed Changes
Copilot reviewed 111 out of 111 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
ResPackage.java | Removed the getConfig() method, since meta access is now provided via the POJO. |
ResourcesDecoder.java | Replaced usage of loadMainPkg() with loadMainPackage() and overhauled decodeManifest logic to simplify manifest decoding and SDK info updates. |
Framework.java | Renamed variable frameTag to tag to improve naming consistency. |
YamlWriter, YamlStringEscapeUtils, YamlSerializable, YamlReader, YamlLine | Adjusted package names and minor condition updates for consistency. |
VersionInfo.java, UsesFramework.java, SdkInfo.java, PackageInfo.java | Converted public fields to private members with accessor methods according to POJO best practices. |
ApkInfo.java | Refactored methods to use the new meta classes, added proper null checks, and updated serialization methods. |
CantFindFrameworkResException.java, ApkDecoder.java, ApkBuilder.java, AaptInvoker.java, TypedValue.java, Main.java | Updated references to the refactored meta classes and improved constant formatting and method call consistency. |
brut.apktool/apktool-lib/src/main/java/brut/androlib/meta/ApkInfo.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess with how much upper casing is going on to the hex, I might see if spotless or something can just lint those.
Let me know if you are done, just want to take a closer look at the ARSC changes otherwise it seems good.
Move: * brut.util.AaptManager -> brut.androlib.AaptManager * brut.androlib.BackgroundWorker -> brut.util.BackgroundWorker * brut.androlib.meta.Yaml* -> brut.yaml Removed useless "throws" on signatures of Yaml functions, none of the Yaml functions throw any managed exceptions, it's a perfectly generic set of classes that deserves a dedicated module. Most of data in arsc is encoded as unsigned integers, so normally we'd use readUnsignedByte/Short where possible (both return int) to ensure the values are never negative. Java doesn't have any valid unsigned counterpart for readInt, so we'll have to live with it, it works for now. Java was never good for dealing with raw binary data.
That Copilot is pretty cool, never seen that in action on GitHub. By the way, AOSP has at least 3 different variations of how resource qualifiers should be formatted, no consistency at all and some of them are nonsense that aapt2 can't read. I based my changes on how aapt2 actually parses the qualifiers, which is what we care about when we want to recompile an app. |
Make command line commands and options great again. Each command has its own valid options, verified properly like any good CLI application. Instead of checking hasOption(shortName/longName), we do hasOption(Option) on the option object, which maintains sanity and very easy to manage. "allOptions" collection is no longer needed.
OK, now I'm really done. Don't feel like anything else in need of urgent rework. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Are all the options intended one too much? I see this, but expect this.
see this
expect this |
You're probably right, but I find it more readable when it's closer to the Option.builder() call. Apktool/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/AXmlResourceParser.java Lines 457 to 460 in 2b2efb1
Apktool/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/data/value/ResFlagsAttr.java Lines 175 to 177 in 2b2efb1
and here it's more indent: Apktool/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/StyledString.java Lines 141 to 148 in 2b2efb1
Apktool/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java Lines 617 to 621 in 2b2efb1
|
imo this
makes less sense, because if you move Option.builder() to the next line, then I'd write something like this:
so the single-indent is reserved for what's after = whether it's actually on a new line or not, but that's just a preference. I can adjust the indentation however you prefer, I'm not religious about it, I'm only religious about making it consistent. XD |
Yeah I guess I shouldn't complain until there is a linter (spotless?) that just enforces it and does it all. |
-api or --api-level not getting recognize at all in repacking apks. |
Ah I see. Maybe our loading since its gated behind the advanced flag is causing it to not recognize the flag. I'll investigate when home today, unless @IgorEisberg beats me to it. |
Apktool is a command-based tool, so having
Forcing API is meant for baksmali, specifically for decoding JARs where there's no AndroidManifest.xml.
Nope, everything is as intended. There's a reason we keep minSdkVersion in apktool.yml even for JARs. |
so what api level will be stored in apktool.yml ? minSdkVersion or -api provided value? |
cause i unpacked some android 15 apks and they stored even though i provided -api 34 in decoding command, whats use of -api value in decoding then? also, not all want to build with -api version 35, Xiaomi uses older version of jars as seen in header of it, so i want to build with older api. |
For APK it's retrieved from AndroidManifest.xml, for JARs it's retrieved automatically from baksmali. |
Then you misuse the tool. If the APK has minSdkVersion of 35, then I'm not sure what magic you expect to happen that will turn it to depend on 34 instead. Again, |
you are wrong here! baksmali not picking up correct api level as seen in repacks! see the original classes.dex file, it has 039 version jar, and the repacked file i did with this new apktool, it packed with 041 which is incompatible in previous apktool, using -api value was actually affecting classes.dex compilation |
Yes, as I already said, you are misusing the tool. If you want dex version 039 then don't use the |
well, seems like removing -api totally from decompiling and recompiling still generates 041 version dex files. i dont know what else needed to get older type output, its just too much confusion! whats issue in adding back -api option simply? |
baksmali tool itself has option to get an api value whatever it is, also, i dont understand how baksmali will get value from stock apk? we are not providing any stock apk to build command, so it will definitely use minSdkVersion for api which is wrong |
Hassan, what are you talking about? How is minSdkVersion wrong? I'm getting |
bro, am not using apktool for jars like framework.jar and services.jar etc, i use smali/baksmali for them but the dex files present inside apks are issue, how 29 will be set for those classes.dex files which are inside apks? |
Because apktool was previously accepting all of the options regardless of which command is used, now it enforces correct usage, like every good tool should do. A good tool should not allow misusage.
I'm not bro. If the APK has minSdkVersion of 35, then yes smali will assemble dex 041. If you think it's a problem you can report it on smali repo. Still, dex 041 is perfectly compatible with Android 15, so I don't see what your problem is. You can't use an APK with minSdkVersion 35 on lower versions of Android anyway. |
041 jar is an issue! see this, header size error due to 041 classes.dex file |
just got 1 of your rom's apk file from that channel, and i can see 039 version classes.dex file. how you are using 039 for yourself and forcing others to use 041? why? |
Because I'm using custom smali/baksmali. I don't agree with the 040 and 041 being forced, the maintainers of the smali repo don't seem to understand that APKs/JARs with those dex versions don't exist in the wild. This incompatibility issue sounds like smali issue to me, not apktool. |
so you are using custom stuff your way and forcing others to not use an option which baksmali itself provides? -a option in smali is for setting api, which was reading it from apktool -api command, so how its a misuse? smali/baksmali maintainer doing all well, not forcing anyone to use 041 if base apk is from android 15 rom |
Smaling with API higher than 29 produces dex 040 or 041, how is it "doing well" exactly? If you can't see the root of the problem, I have no reason discussing this further. It's easier barking here instead of complaining on smali repo, of course. Up to Connor how he wants to handle this. |
well, i hope you know that smali has an option "-a" which is to set api version someone wanna use. if i use api 34 there, then dex files are of version 040, which clearly make sense, smali has all dex version support properly and for each android. |
@iBotPeaches looks like smali is broken and builds 041 dex with 112-byte headers instead of the expected 120-byte HeaderV41 headers. Those 041 dex literally can't be baksmali'd again. Which would still make it a smali issue... |
I think since we are still on the 2.x branch we could bring back the ability to override the api-level (which overrides apktool.yml) as its passed to smali. I believe maybe those workarounds are used to workaround the bugs on 040/041 dex versions |
there is another suggestion though, add an entry for dexversion in apktool.yml under minsdkversion. so it correctly follows minsdkversion for resources etc and dexversion for dex compilation, that way, we dont need -api parameter at all this will keep the recompiled apk as close to sourced one. |
Alright, but that still doesn't solve the possibility of building 041 dex by default if minSdkVersion >= 35 and It's related to this: #3725 I never encountered the issue myself because in my smali/baksmali I restored the old versions map before Google decided to shove their 040 and 041 in there:
But since you're using stock smali/baksmali for apktool, best to just put an upper limit of 29 on API level for smali, to ensure dex <= 039. More than 039 doesn't even exist in the wild, and 041 is broken completely, so even outputting those dex files shouldn't be a thing. |
make sense, thanks for understanding that. appreciated |
Haven't changed anything regarding that... what you're saying makes no sense. |
yes, my bad, i mistakenly press a different menu and instantly removed comment, peace :) |
Wanted to make that change back when I converted Config class to POJO, finishing the job now. This will guarantee safe access to all meta classes (moved from brut.androlib.apk to brut.androlib.meta to make more sense). All non-primitive fields are guaranteed to never be null. Outputs clean apktool.yml without useless fields that don't affect the rebuild procedure. Still backwards compatible, just cleaner output, especially for JARs.
Cleaned some logic in a few classes, especially related to updateApkInfo and loading of libraries/frameworks. It was a mess that was difficult to make sense of.
Test issue1235 removed, it's a aapt1 duplicate of aapt2's issue2328/debuggable-false.
Misc style tweaks for consistency.
Tested on a ROM decompile/recompile, no regression detected.