How tencent/tinker works
Project Type and Purpose
• Tinker is an Android hot‑fix solution library (open‑source tool) that supports dex, native library (.so) and resource updates without reinstalling the APK.
• It consists of build‑time components (Gradle plugin, CLI, annotation processor, patch‑building libraries) and runtime components (loader modules, core Android libraries, patch applier).
File‑Structure Analysis
• Top‑level directories:
• gradle, build scripts, publishing logic
• third-party (forks of AOSP dexutils, bsdiff, ziputils)
• tinker-android (annotation support, annotation processor, no-op stubs, real runtime lib, runtime loader)
• tinker-build (CLI tool, Gradle plugin, patch‑lib core patch‑generation engine)
• tinker-commons (shared dex‑patch applier utilities)
• tinker-sample-android (sample Android app demonstrating integration)
• Patterns: separation of build‑time vs. runtime modules; annotation processing to generate Application wiring; plugin hooks into Android build pipeline; multi‑module Gradle project.
README Insights
• Shows how to “apply” the Gradle plugin, add dependencies, annotate ApplicationLike, and subclass TinkerApplication.
• Indicates core phases: patch building (CLI or Gradle), annotation (tinker-android-anno), runtime loading (tinker-android-loader, tinker-android-lib).
Main Components
a. Build‑Time Components
• Tinker‑Patch‑Gradle‑Plugin (Gradle plugin module)
• Tinker‑Patch‑CLI (standalone Java CLI)
• Annotation Processor (tinker-android-anno)
• Patch‑Lib Engine (tinker-build/tinker-patch‑lib + tinker-commons)
• Third‑Party Utilities (dexutils, bsdiff, ziputils)
b. Runtime Components
• Tinker‑Android‑Loader (classloader hooks, hotplug interceptors)
• Tinker‑Android‑Lib (patch applier: DexDiffPatchInternal, ResDiffPatchInternal, SoDiffPatchInternal, ArkHotDiffPatchInternal)
• ApplicationLike / TinkerApplication integration
• Android OS (classloader, resource manager)
c. Sample App
• SampleApplicationLike, SampleApplication
• Sample patch listeners & reporters
d. External Dependencies
• Android Gradle Plugin, AAPT, Java/Kotlin toolchain
Relationships & Data Flows
• Build‑time:
• Developer invokes Gradle build → Gradle plugin invokes patch-lib + third‑party tools to diff old vs. new APK → outputs patch files (classes.dex, patch.apk)
• CLI alternative uses patch‑lib engine directly
• Annotation processor runs during compile to generate Application wiring classes
• Runtime:
• On Application start, TinkerApplication initializes TinkerInstaller → loader module injects new Dex, So, resources into classloader & resource system → patch applier (core lib + commons) applies incremental diffs
• PatchListener and LoadReporter receive callbacks
• Sample app exercises the above flow.
Architectural Patterns & Principles
• Modular separation: build‑time vs. runtime vs. sample vs. third‑party
• Plugin pattern: Gradle plugin hooks into Android build lifecycle
• Annotation processing: code‑generation to decouple compile‑time wiring
• Strategy pattern: Diff/Patch algorithms (Dex, resource, library)
• Chain of responsibility: loader hotplug interceptors
Essential Elements Checklist
• [ ] Separate build‑time vs. runtime vs. sample vs. external
• [ ] Show patch file creation and injection flows
• [ ] Indicate use of third‑party utils (dexutils, bsdiff, ziputils)