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:
- Command Line Option
- Use option
-I
or--init-script
to specify the Initialization Scriptsopen in new window file on the command line, it's flexible and able to limit the scope of Initialization Scriptsopen in new window
- Use option
- Gradle Directory
- Put a file called
init.gradle
(orinit.gradle.kts
for Kotlin) in theUSER_HOME/.gradle/
directory. - Put a file that ends with
.gradle
(or.init.gradle.kts
for Kotlin) in theUSER_HOME/.gradle/init.d/
directory. - Put a file that ends with
.gradle
(or.init.gradle.kts
for Kotlin) in theUSER_HOME/init.d/
directory.
- Put a file called
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
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
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.