fix: resolve #1192 — 所有静态的方法和常量都无法被合并#1795
Open
Nam0101 wants to merge 3 commits into
Open
Conversation
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>
Member
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fix: resolve #1192 — 所有静态的方法和常量都无法被合并
Problem
Severity:
Critical| File:tinker-build/tinker-patch-lib/src/main/java/com/tencent/tinker/build/dexpatcher/algorithms/diff/ClassDataSectionDiffAlgorithm.javaThis file (in the tinker-build module not shown in the truncated tree) is where
class_data_itemdeltas 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 newpublic staticmember, 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
staticFieldsSizeanddirectMethodsSizewritten 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
Note: this change was drafted with AI assistance and reviewed locally before submission.