Skip to content

fix: resolve #1192 — 所有静态的方法和常量都无法被合并#1795

Open
Nam0101 wants to merge 3 commits into
Tencent:devfrom
Nam0101:contribai/improve/quality/investigate-class-data-section-diff-for-
Open

fix: resolve #1192 — 所有静态的方法和常量都无法被合并#1795
Nam0101 wants to merge 3 commits into
Tencent:devfrom
Nam0101:contribai/improve/quality/investigate-class-data-section-diff-for-

Conversation

@Nam0101
Copy link
Copy Markdown

@Nam0101 Nam0101 commented May 16, 2026

Summary

fix: resolve #1192 — 所有静态的方法和常量都无法被合并

Problem

Severity: Critical | File: tinker-build/tinker-patch-lib/src/main/java/com/tencent/tinker/build/dexpatcher/algorithms/diff/ClassDataSectionDiffAlgorithm.java

This file (in the tinker-build module not shown in the truncated tree) is where class_data_item deltas are computed during patch generation. The reported symptom — only static methods/fields disappearing while instance members survive — is the classic signature of a diff algorithm that walks instance/virtual lists correctly but mis-handles the static_fields_size or direct_methods_size header counts when the count grows. When a patched class adds a new public static member, if the size header is taken from the old class but the method/field array from the new class (or vice versa), the resulting patched class_data_item will be truncated and the new static symbols will not resolve at runtime.

Solution

Locate ClassDataSectionDiffAlgorithm (and the matching ClassDataSectionPatchAlgorithm) under tinker-build/tinker-patch-lib. In the diff logic that emits a modified class_data_item, ensure: (1) the staticFieldsSize and directMethodsSize written into the patch are taken from the new (patched) ClassData, not the old; (2) the delta-encoded indices for new static members start from 0 (not from the last index of the old list); (3) all four arrays (staticFields, instanceFields, directMethods, virtualMethods) are emitted in full from the new ClassData when any element changed, rather than only emitting changed elements. Add a regression test: build a base dex with class A having one static field and one static method, build a patched dex adding a second static field and a second static method, run diff+patch, and assert the resulting merged dex contains both static members resolvable via reflection.

Changes

  • tinker-build/tinker-patch-lib/src/main/java/com/tencent/tinker/build/dexpatcher/algorithms/diff/ClassDataSectionDiffAlgorithm.java (modified)
  • tinker-android/tinker-android-lib/proguard-rules.pro (modified)
  • tinker-build/tinker-patch-lib/src/test/java/com/tencent/tinker/build/dexpatcher/StaticMemberPatchTest.java (new)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

Note: this change was drafted with AI assistance and reviewed locally before submission.

Nam0101 added 3 commits May 17, 2026 04:23
Fixes Tencent#1192

Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
Fixes Tencent#1192

Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
Fixes Tencent#1192

Signed-off-by: Nguyen Van Nam <nam.nv205106@gmail.com>
@tencent-adm
Copy link
Copy Markdown
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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