bytedance / ByteX

ByteX is a bytecode plugin platform based on Android Gradle Transform API and ASM. 字节码插件开发平台
Apache License 2.0
3.15k stars 463 forks source link
asm bytecode gradle gradle-plugin

English | 简体中文

ByteX(Infinite Possibilities)

logo

GitHub license

Powered by ByteDance TikTok & Douyin Android team.

ByteX is a bytecode plugin platform based on Android Gradle Transform Api and ASM.

(Maybe you can think of it as a socket with unlimited plugs?)

In the apk building process, each plugin is completely independent. It not only can run independently from the ByteX host, but also can be automatically integrated into the host into a single Transform along with other plugins.

What's more, each plugin's code is decoupled from one another, as well as their host, which makes it extensible and highly efficient for the development of new plugins.

Background

If all features are developed as a separate plugin, each plugin will cost 10+s, and the compilation time will increase linearly.

But if the iterative development in only one plugin module will make it more and more cluttered, for the code is deeply coupled.

So an idea was raised. It could make sense to build a bytecode plugin platform, and the new feature can be extended based on it as a new plugin.

Feature

Structure

structure

TransformEngine

Reading all the class files in the project and Android SDK, and writing back to the specified directory.

base-plugin

ByteX host.

common

Basic code library, including class diagram construction, logs, interfaces provided to various plugins.

other plugin modules

Depending on common module and focusing on bytecode operation.

Quick Start

Add those configuration code to your build.gradle, and apply your plugins on demand.

buildscript {
    ext.plugin_version="0.3.0"
    repositories {
        google()
        jcenter()
        maven {
            url "https://artifact.bytedance.com/repository/byteX/"
        }
    }

    dependencies {
        classpath "com.bytedance.android.byteX:base-plugin:${plugin_version}"
        // Add bytex plugins' dependencies on demand
        classpath "com.bytedance.android.byteX:refer-check-plugin:${plugin_version}"
        // ...
    }
}

apply plugin: 'com.android.application'
// apply bytex host
apply plugin: 'bytex'
ByteX {
    enable true
    enableInDebug false
    logLevel "DEBUG"
}

// apply bytex plugins on demand...
apply plugin: 'bytex.refer_check'
// ...

Note: If ByteX host is not applied, there is no difference between ByteX plugins and ordinary ones, and all of them will run separately. On the contrary, all ByteX plugins can be automatically merged into one single Transform with the help of the ByteX host.

Plugins

Apps Using ByteX

抖音 tiktok 今日头条
抖音 Tik Tok 今日头条
火山小视频 lark 多闪
火山小视频 飞书 多闪
FaceU 轻颜 飞聊
FaceU激萌 轻颜 飞聊

What else can the ByteX do?

There are more than 25 plugins developed based on ByteX in ByteDance (We only open sourced some of them). You can quickly develop the following related plugins based on ByteX:

Contribution

If you have some creative ideas and demands related to bytecode, come to join us to develop a new bytecode plugin based on ByteX!

Please read through our Developer API.

Thanks

Contact us

If you have any question or advice about ByteX, feel free to join our WeChat group.

WeChat Group

Besides, sending email to yangzhiqian@bytedance.com or tanlehua@bytedance.com is also available for you.

Change Log

Change Log

License

Apache 2.0