Booster Quality Optimization Toolkit

website·Indexed 32 days ago

https://booster.johnsonlee.io/

A lightweight and extensible quality optimization toolkit designed for Android. Booster provides non-intrusive tools for bytecode manipulation, resource shrinking (PNG, WebP, and ZIP compression), performance optimization (WebView preloading, SharedPreferences), and bug fixing for common Android system crashes. It includes a comprehensive bytecode processing pipeline, support for ClassTransformers, and detailed references for JVM instructions and class file formats.

Tokens
26.7K
Snippets
112
Records
171
Agent score
57%

What's inside Booster

  1. Overview of Booster quality optimization toolkit

    Booster is a lightweight, extensible quality optimization toolkit designed for mobile applications to address issues related to performance, stability, and package size as app complexity increases. It is implemented as a Gradle Plugin and provides a framework for monitoring and optimizing code, resources, dynamic libraries, and dependencies. Key capabilities include:

    • Stability & Size: Can increase stability by 15%–25% and reduce package size by 1MB–10MB+.
    • Static Analysis: Detects performance issues, security risks, and app store policy violations during the build process.
    • Non-intrusive Optimization: Uses Aspect-Oriented Programming (AOP) to apply global optimizations without requiring changes to business code.
    • Troubleshooting: Provides a Transformer SPI for bytecode instrumentation and class inheritance analysis, including a thread renaming feature to improve APM (Application Performance Monitoring) integration.
  2. Overview of Booster for mobile application optimization

    Booster is an open-source tool designed to optimize the quality and user experience of large-scale mobile applications, specifically addressing challenges where mobile device computing power lags behind the growth of app complexity. It is particularly useful for Android application developers looking to improve engineering productivity and app performance.
  3. Overview of Booster Static Analysis

    Booster provides a bytecode-oriented static analysis tool (booster-task-analyser) designed to detect potential issues before product release that source-code-based tools (like SonarQube) might miss. It generates a call graph and analysis reports to help developers identify:

    1. Potential performance issues (e.g., API calls blocking the main/UI thread).
    2. Risky API calls.
    3. Class dependencies.
  4. Optimize Android thread management using Booster

    Booster provides a non-intrusive solution for thread management by replacing standard thread creation instructions with customized method calls during the compile-time transform phase. This approach targets the most common ways threads are created in Android, including Thread and its subclasses, ThreadPoolExecutor, Executors, ThreadFactory, AsyncTask, and Timer.
  5. Perform bytecode transformation using the Transformer abstraction

    In Booster, all bytecode-related operations are handled via the Transformer interface. This abstraction takes a bytecode binary as input and returns a transformed bytecode binary. Because it is framework-agnostic, developers can use their preferred bytecode manipulation library. Booster provides two built-in implementations: AsmTransformer (ASM-based) and JavassistTransformer (Javassist-based).
  6. Understand how Gradle incremental builds work in Booster

    Booster supports incremental builds for Transform and specific compression tasks (pngquant and cwebp). Gradle determines if a task is UP-TO-DATE by comparing the current inputs and outputs against the results of the previous successful execution.

    • Inputs: Anything that affects the output result, including input file paths, file content hashes, build environment settings, and target version numbers.
    • Outputs: The set of files produced by the task and their content hashes.

    If the inputs and outputs remain unchanged, Gradle skips the task. If they differ, the task is executed. Note that incremental builds require a task to have at least one defined output to function.

  7. Implement multi-round transforms using Collector and Supervisor

    In Booster, the Transformer typically follows a single-round pipeline. For cases where complete information must be collected from bytecode before transformation can proceed, Booster provides the Collector and Supervisor APIs.

    • Collector: A functional complement to the unidirectional pipeline used to collect information and determine if pipeline inputs need to be updated.
    • Supervisor: A specialized Collector that observes the pipeline and collects information without affecting the update of pipeline inputs.
  8. Understand Booster's resource deredundancy logic

    Booster solves the problem of inconsistent resource adaptation across different screen densities (common in many apps) by implementing a specific removal strategy. Instead of splitting APKs (which can cause crashes if a resource is missing for a specific density), Booster:

    1. Groups resources by type.
    2. Groups resources of the same type by name.
    3. Sorts resources with the same name by density from high to low.
    4. Keeps only the resource with the highest density and removes all others of the same type and name.

    Booster also respects the android:supportsRtl attribute in the AndroidManifest.xml to decide whether to keep resources with the same density but different layout directions.

  9. Integrate Booster with Android Gradle Plugin Transform API

    Booster uses the Android Gradle Plugin (AGP) Transform API (supported in AGP 3.0.0+) to modify class files before they are converted to dex. It achieves this by registering BoosterTransform with the Android Extension. The Transform API allows third-party plugins to process bytecode by defining specific Content Types and Scopes.
  10. Booster Project Overview and Key Features

    Booster is a tool designed to optimize app quality efficiently with a minimal setup for Gradle projects. It is designed to be completely non-intrusive, allowing for global app optimization without requiring modifications to the business code.

    Key technical specifications include:

    • Compatibility: Supports Android Gradle Plugin (AGP) 3.0 and above.
    • Architecture: Uses a plug-in architecture based on SPI (Service Provider Interface), allowing developers to extend functionality via the Booster API.
    • Execution: Decoupled from Gradle, meaning it can run as a Java standalone application.
    • Bytecode Manipulation: Supports both AMS and Javassist frameworks.
  11. Prevent intermittent Android system crashes with Booster

    Booster can prevent crashes caused by the Android system (e.g., DeadObjectException, RuntimeException, WindowManager$BadTokenException, Resources.NotFoundException) that occur on the main thread. It achieves this by using reflection to set a Handler.Callback for ActivityThread.mH.mCallback. To avoid masking actual app bugs, Booster only catches exceptions where the stack trace contains exclusively system classes or whitelisted packages.