Skip to content
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

fix: support featureFlags anywhere #3771

Merged
merged 2 commits into from
Jan 19, 2025

Conversation

IgorEisberg
Copy link
Contributor

Checked aapt2 source and how aapt2 responds to featureFlags specified in tags other than "permission". Apparently it's allowed to appear on any tag inside "manifest" as it's being pre-processed. An easy fix.

Fixes #3768

@Tulsadiver
Copy link

Tulsadiver commented Jan 17, 2025

That worked but that feature flag is still mentioned at the bottom. Do you have any idea what causes all of the "attributes not found" that pops up after "feature flags" is fixed? It has been occurring on SystemUIGoogle.apk since Android 14, I believe.

Rebuild only...
Compiling first pass...
I: Using Apktool v2.11.0-3-4b2c9abe-SNAPSHOT on SystemUIGoogle.apk with 4 threads
I: Smaling smali folder into classes.dex...
I: Smaling smali_classes2 folder into classes2.dex...
I: Building resources with aapt2...
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\animator\design_appbar_state_list_animator.xml:4: error: attribute state_liftable (aka com.android.systemui:state_liftable) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\animator\design_appbar_state_list_animator.xml:4: error: attribute state_lifted (aka com.android.systemui:state_lifted) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\animator\m3_appbar_state_list_animator.xml:4: error: attribute state_liftable (aka com.android.systemui:state_liftable) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\animator\m3_appbar_state_list_animator.xml:4: error: attribute state_lifted (aka com.android.systemui:state_lifted) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\animator\m3_card_elevated_state_list_anim.xml:7: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\animator\m3_card_state_list_anim.xml:7: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\animator\mtrl_card_state_list_anim.xml:4: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\color\m3_card_foreground_color.xml:5: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\color\m3_card_stroke_color.xml:9: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\color\mtrl_card_view_foreground.xml:5: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\color\mtrl_card_view_foreground.xml:6: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\color\mtrl_card_view_ripple.xml:5: error: attribute state_dragged (aka com.android.systemui:state_dragged) not found.
W: E:\3Custom14Pixelscript\SystemUIGoogle\res\layout\status_bar_expanded.xml:10: error: attribute viewType (aka com.android.systemui:viewType) not found.
W: error: failed linking file resources.
Exception in thread "main" brut.androlib.exceptions.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\tulsa\AppData\Local\Temp\brut_util_Jar_21990495772156703396196932067120995143.tmp, link, -o, C:\Users\tulsa\AppData\Local\Temp\APKTOOL5796029051260127211.tmp, --allow-reserved-package-id, --package-id, 127, --min-sdk-version, 35, --target-sdk-version, 35, --version-code, 35, --version-name, 15, --no-auto-version, --no-version-vectors, --no-version-transitions, --no-resource-deduping, --no-compile-sdk-metadata, --warn-manifest-validation, --enable-compact-entries, --feature-flags, com.android.wm.shell.enable_retrievable_bubbles=true, -I, framework-3Custom14Pixelscript\1.apk, --manifest, E:\3Custom14Pixelscript\SystemUIGoogle\AndroidManifest.xml, E:\3Custom14Pixelscript\SystemUIGoogle\build\resources.zip]
        at brut.androlib.AaptInvoker.invokeAapt2(AaptInvoker.java:213)
        at brut.androlib.AaptInvoker.invoke(AaptInvoker.java:62)
        at brut.androlib.ApkBuilder.buildResourcesFull(ApkBuilder.java:352)
        at brut.androlib.ApkBuilder.buildResources(ApkBuilder.java:268)
        at brut.androlib.ApkBuilder.build(ApkBuilder.java:93)
        at brut.apktool.Main.cmdBuild(Main.java:322)
        at brut.apktool.Main.main(Main.java:110)
Caused by: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\tulsa\AppData\Local\Temp\brut_util_Jar_21990495772156703396196932067120995143.tmp, link, -o, C:\Users\tulsa\AppData\Local\Temp\APKTOOL5796029051260127211.tmp, --allow-reserved-package-id, --package-id, 127, --min-sdk-version, 35, --target-sdk-version, 35, --version-code, 35, --version-name, 15, --no-auto-version, --no-version-vectors, --no-version-transitions, --no-resource-deduping, --no-compile-sdk-metadata, --warn-manifest-validation, --enable-compact-entries, --feature-flags, com.android.wm.shell.enable_retrievable_bubbles=true, -I, framework-3Custom14Pixelscript\1.apk, --manifest, E:\3Custom14Pixelscript\SystemUIGoogle\AndroidManifest.xml, E:\3Custom14Pixelscript\SystemUIGoogle\build\resources.zip]
        at brut.util.OS.exec(OS.java:143)
        at brut.androlib.AaptInvoker.invokeAapt2(AaptInvoker.java:209)
        ... 6 more

framework-res.zip
SystemUIGoogle.zip

@IgorEisberg
Copy link
Contributor Author

It's mentioned at the bottom because it's passed to aapt2, as intended.
The errors you're getting are unrelated to this issue.
The APK is in fact missing attributes and you'll have to add them yourself if you want to rebuild the APK.
Likely caused by some nonsense in the AOSP build system.

@Tulsadiver
Copy link

Tulsadiver commented Jan 17, 2025 via email

@iBotPeaches
Copy link
Owner

Triple ticks in the future @Tulsadiver to save formatting - saves my eyes trying to read this. @IgorEisberg - I haven't messed with flags yet, so I'll take this down and mess with sample apk to wrap my head around this.

In terms of those attr errors - last time I investigated that in 2023 it was a greedy build system removing the attributes and Apktool not being greedy enough to remove unused attrs.

@Tulsadiver
Copy link

Tulsadiver commented Jan 17, 2025 via email

@IgorEisberg
Copy link
Contributor Author

IgorEisberg commented Jan 17, 2025

Triple ticks in the future @Tulsadiver to save formatting - saves my eyes trying to read this. @IgorEisberg - I haven't messed with flags yet, so I'll take this down and mess with sample apk to wrap my head around this.

Wrap your head around what? Feature flags is a simple concept. You're overthinking it.

In terms of those attr errors - last time I investigated that in 2023 it was a greedy build system removing the attributes and Apktool not being greedy enough to remove unused attrs.

If they were unused that would make sense, but they are used in multiple layouts, which makes this a big question mark.
Been handling this issue since Android 14 using a custom solution both in Apktool and an external tool to inject missing definitions and replace the raw values with valid value names in the layouts.

Checked aapt2 source and how aapt2 responds to featureFlags specified
in tags other than "permission". Apparently it's allowed to appear on
any tag inside "manifest" as it's being pre-processed. An easy fix.
@iBotPeaches
Copy link
Owner

If you can uncomment my test and confirm it works on this branch - should be good to go. 8886275

@IgorEisberg
Copy link
Contributor Author

IgorEisberg commented Jan 18, 2025

Tweaked your test for consistency with the other ApkInfo tests to not add even more redundancy. Works fine.

Notes:

  • Like doNotCompress, featureFlags cannot be null, it's initialized on definition. Even if it were to be null, the test would fail with a NullPointerException.
  • assertTrue is enough since featureFlags.get() returns a Boolean and the assertion implicitly calls Boolean.booleanValue() which will fail the test with NullPointerException if the key doesn't exist or is null (which will never happen unless someone in the future messes it up).

@iBotPeaches iBotPeaches merged commit e547948 into iBotPeaches:master Jan 19, 2025
25 checks passed
@iBotPeaches iBotPeaches added this to the v2.12.0 milestone Jan 19, 2025
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.

Feature Flags - API 35 not working
3 participants