VasDolly

repository·master·Indexed 25 days ago

https://github.com/tencent/vasdolly

A high-performance multi-channel packaging tool for Android that supports V1, V2, and V3 signing schemes. It provides a CLI (VasDolly.jar), a Gradle plugin for direct compilation or rebuilding from base APKs, and low-level Reader and Writer APIs (ChannelReader, IdValueReader, ChannelWriter, IdValueWriter) for managing channel information and custom ID-Value pairs.

Tokens
3K
Snippets
11
Records
24
Agent score
85%

What's inside VasDolly

  1. Verify multi-channel APK installation compatibility

    master

    The verify module is responsible for checking whether the generated multi-channel APKs can be correctly installed on all Android systems. It relies on Google's apksig tool for verification.

    Note: This is implemented as a standalone Java module because apksig is compiled with Java 8, which is incompatible with standard Android modules (due to Dex limitations regarding version 52 byte code).

  2. Add channel information to APKs

    master

    VasDolly provides several ways to add channel information to a base APK using the put command:

    1. Via comma-separated strings: Specify multiple channels as a single string.
    2. Via a channel file: Provide a text file containing channel names.
    3. Fast Mode: Use the -f flag to skip strong validation, which can increase speed by over 10x.
    4. Multi-threaded (V1 only): Use the -mtc flag with a channel file to enable multi-threading for V1-based multi-channel packaging, suitable for large numbers of channels.
  3. Add the VasDolly Writer dependency

    master

    To use the low-level ChannelWriter and IdValueWriter classes for fine-grained control over channel information and custom ID-Value pairs, add the following dependency to your project's dependencies block:

    dependencies {
        compile 'com.tencent.vasdolly:writer:3.0.4'
    }
  4. Generate Multi-Channel APKs via Gradle (Direct Compilation)

    master

    To generate multi-channel APKs directly from your project, configure the channel block in your app-level build.gradle.

    Configuration Options:

    • channelFile: Path to the channel file.
    • outputDir: Output directory (default: project.buildDir/channel).
    • apkNameFormat: Naming pattern. Available tokens: ${appName}, ${versionName}, ${versionCode}, ${flavorName}, ${buildType}, ${appId}, ${buildTime}.
    • fastMode: If true, skips verification (increases speed by >10x, default false).
    • buildTimeDateFormat: Format for ${buildTime} (default: yyyyMMdd-HHmmss).
    • lowMemory: If true, only reads signature blocks, central directory, and EOCD into memory (useful for V2 signatures on low-memory devices, default false).

    Commands:

    • gradle channelDebug: Generates Debug multi-channel APKs.
    • gradle channelRelease: Generates Release multi-channel APKs.

    Temporary Testing: You can pass channels via command line using the -Pchannels property, which takes precedence over files: gradle channelDebug -Pchannels=channel1,channel2

    channel {
        channelFile = file("/Users/leon/Downloads/testChannel.txt")
        outputDir = new File(project.buildDir,"xxx")
        apkNameFormat ='${appName}-${versionName}-${versionCode}-${flavorName}-${buildType}'
        fastMode = false
        buildTimeDateFormat = 'yyyyMMdd-HH:mm:ss'
        lowMemory = false
    }
  5. Regenerate Multi-Channel APKs from an Existing Base APK

    master

    If you already have a base APK, use the rebuildChannel block to generate multiple versions.

    Configuration Options:

    • channelFile: Path to the channel file.
    • baseApk: Path to the existing base APK (Required). The filename 'base' in the path will be replaced by the channel name.
    • outputDir: Output directory (default: project.buildDir/rebuildChannel).
    • fastMode: If true, skips verification (default false).
    • lowMemory: If true, uses low-memory mode for V2 signatures (default false).

    Commands:

    • gradle rebuildChannel: Generates the multi-channel APKs.

    Temporary Testing: gradle rebuildChannel -Pchannels=channel1,channel2

    rebuildChannel {
      channelFile = file("/Users/leon/Downloads/testReChannel.txt")
      baseApk = new File(project.rootDir, "/baseApk/app_base.apk")
      outputDir = new File(project.buildDir, "rebuildChannel")
      fastMode = false
      lowMemory = false
    }
  6. Install VasDolly Plugin and Helper Library

    master

    To use VasDolly for multi-channel packaging, follow these three steps:

    1. Add the Plugin dependency to your root project's build.gradle:
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath 'com.tencent.vasdolly:plugin:3.0.6'
    }
    1. Apply the Plugin in your app-level build.gradle:
    apply plugin: 'com.tencent.vasdolly'
    1. Add the Helper library dependency in your app-level build.gradle to enable reading channel information at runtime:
    dependencies {
        api 'com.tencent.vasdolly:helper:3.0.6'
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath 'com.tencent.vasdolly:plugin:3.0.6'
    }
    
    // In app build.gradle
    apply plugin: 'com.tencent.vasdolly'
    
    dependencies {
        api 'com.tencent.vasdolly:helper:3.0.6'
    }
  7. Add the VasDolly Reader dependency

    master

    To use the low-level ChannelReader and IdValueReader APIs for fine-grained channel information retrieval, add the following dependency to your build.gradle file:

    dependencies {
        compile 'com.tencent.vasdolly:reader:3.0.4'
    }
  8. Configure Channel Lists for VasDolly

    master

    You can configure channel lists using two methods. The final list is the sum of both.

    1. Via gradle.properties: Specify a filename (must be in the root directory, one channel per line).

    channel_file=channel.txt

    1. Via Gradle DSL: Use the channelFile property within the channel or rebuildChannel blocks.
    channel {
        channelFile = file("/path/to/testChannel.txt")
    }
    
    rebuildChannel {
        channelFile = file("/path/to/testReChannel.txt")
    }
  9. Use ChannelWriter to manage channel information

    master
    The ChannelWriter class provides interfaces for adding or removing channel information in an APK. It supports both V1 and V2 signatures. Use this class when you need to programmatically inject or strip channel metadata from your application packages.