Skip to content

Comments

fix: wrong radix multipliers for complex values#4070

Closed
huanli233 wants to merge 1 commit intoiBotPeaches:mainfrom
huanli233:fix/complex-fraction-decoding
Closed

fix: wrong radix multipliers for complex values#4070
huanli233 wants to merge 1 commit intoiBotPeaches:mainfrom
huanli233:fix/complex-fraction-decoding

Conversation

@huanli233
Copy link

What

Fix incorrect decoding of complex fraction/dimension values in binary XML output.

Why

ResXmlEncoders used wrong radix multipliers, causing some values (e.g. -2%) to be decoded into huge incorrect numbers (e.g. -4294963200%).

How

Use the same MANTISSA_MULT / RADIX_MULTS math as AOSP android.util.TypedValue.complexToFloat().

Result

Decoded XML matches aapt2 / jadx behavior for negative fractions/dimensions.

@huanli233 huanli233 force-pushed the fix/complex-fraction-decoding branch from e95d0b3 to 66826ae Compare January 16, 2026 20:48
@huanli233 huanli233 force-pushed the fix/complex-fraction-decoding branch from 66826ae to 5ff7f24 Compare January 16, 2026 20:54
@IgorEisberg
Copy link
Collaborator

IgorEisberg commented Jan 17, 2026

There's no difference between the code you added and the existing code in TypedValue.
You'll have to provide a proper sample because your numbers don't match up with mine.
No idea where you pulled that -4294963200% value from.

Source:

<resources>
    <dimen name="test1">2.0dp</dimen>
    <dimen name="test2">-2.0dp</dimen>
    <dimen name="test3">2.0%</dimen>
    <dimen name="test4">-2.0%</dimen>
</resources>

Decoded as:

<resources>
    <dimen name="test1">2.0dp</dimen>
    <dimen name="test2">-2.0dp</dimen>
    <dimen name="test3">1.9999981%</dimen>
    <dimen name="test4">-1.9999981%</dimen>
</resources>

Which is normal because float has very limited precision, especially in a complex value that also has unit data encoded in it.

@huanli233
Copy link
Author

I apologize for my oversight. I was using apktool-lib for decoding in my layoutlib environment, which may have affected apktool's calls to TypedValue. This pull request did resolve the issue, but it was unnecessary.

This pull request will be closed. Thank you for your reply.

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.

2 participants