Getting Started (Advanced)

Integrating by Init Script

Through the Initialization Scriptsopen in new window provided by Gradle, Booster can be integrated to optimize app performance and stability non-intrusively without modifying the existing code, especially in the CI environment.

Gradle support integration by Initialization Scriptsopen in new window in two forms:

  1. Command Line Option
  2. Gradle Directory
    • Put a file called init.gradle (or init.gradle.kts for Kotlin) in the USER_HOME/.gradle/ directory.
    • Put a file that ends with .gradle (or .init.gradle.kts for Kotlin) in the USER_HOME/.gradle/init.d/ directory.
    • Put a file that ends with .gradle (or .init.gradle.kts for Kotlin) in the USER_HOME/init.d/ directory.

https://docs.gradle.org/current/userguide/init_scripts.html#sec:using_an_init_scriptopen in new window

Take the multi-threading optimizationas the example, creating a file called init.gradle in the root project directory with the content shown as below:

allprojects { project ->
    buildscript {
        ext.booster_version = "5.0.0"
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath "com.didiglobal.booster:booster-gradle-plugin:$booster_version"
            classpath "com.didiglobal.booster:booster-transform-thread:$booster_version"
        }
    }
    repositories {
        google()
        mavenCentral()
    }
    project.afterEvaluate {
        if (project.extensions.findByName('android') != null) {
            project.apply plugin: 'com.didiglobal.booster'
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
allprojects { project ->
    buildscript {
        val booster_version = "5.0.0"
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath("com.didiglobal.booster:booster-gradle-plugin:$booster_version")
            classpath("com.didiglobal.booster:booster-transform-thread:$booster_version")
        }
    }
    repositories {
        google()
        mavenCentral()
    }
    project.afterEvaluate {
        if (project.extensions.getByName("android") != null) {
            project.plugins.apply("com.didiglobal.booster")
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

So that we can integrate with Booster by specifying the Initialization Scriptsopen in new window option on command line:

./gradlew -I init.gradle assembleDebug
1

It's also OK to integrate with Booster by using Gradle directory.