Skip to content

Commit 9e6d75d

Browse files
feat: 默认配置编译加速项
1 parent 0278cba commit 9e6d75d

5 files changed

Lines changed: 76 additions & 31 deletions

File tree

buildSrc/src/main/kotlin/plugin/RocketXPlugin.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ open class RocketXPlugin : Plugin<Project> {
9393
}
9494

9595
appProject.gradle.taskGraph.addTaskExecutionListener(object : TaskExecutionListener {
96-
override fun beforeExecute(p0: Task) {
96+
override fun beforeExecute(task: Task) {
97+
if (task.name.contains("Test") || task.name.contains("Lint")) {
98+
task.enabled = false
99+
}
97100
}
98101

99102
override fun afterExecute(task: Task, state: TaskState) {
@@ -188,9 +191,8 @@ open class RocketXPlugin : Plugin<Project> {
188191
println("transFormList = [\"" + xValue!![0].name + "\"]")
189192
}
190193
}
191-
//并行运行task
192-
appProject.gradle.startParameter.isParallelProjectExecutionEnabled = true
193-
appProject.gradle.startParameter.maxWorkerCount += 4
194+
195+
boostGradleOption(appProject)
194196
}
195197

196198

buildSrc/src/main/kotlin/plugin/utils/InstallApkByAdb.kt

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class InstallApkByAdb(val appProject: Project) {
2222
fun maybeInstallApkByAdb() {
2323
if (isRunAssembleTask(appProject)) {
2424
val android = appProject.extensions.getByType(AppExtension::class.java)
25-
val installTask =
26-
appProject.tasks.maybeCreate("rocketxInstallTask", InstallApkTask::class.java)
25+
val installTask = appProject.tasks.maybeCreate("rocketxInstallTask", InstallApkTask::class.java)
2726
installTask.android = android
2827
android.applicationVariants.forEach {
2928
getAppAssembleTask(RocketXPlugin.ASSEMBLE + it.flavorName.capitalize() + it.buildType.name.capitalize())?.let { taskProvider ->
@@ -58,31 +57,23 @@ class InstallApkByAdb(val appProject: Project) {
5857
AndroidDebugBridge.initIfNeeded(false)
5958
val bridge = AndroidDebugBridge.createBridge(android.adbExecutable.path, false)
6059
var firstLocalDeviceSerinum = ""
61-
bridge?.devices?.forEach {
62-
if (!it.serialNumber.isNullOrEmpty()) {
63-
firstLocalDeviceSerinum = it.serialNumber
64-
return@forEach
60+
run loop@{
61+
bridge?.devices?.forEach {
62+
if (!it.serialNumber.isNullOrEmpty()) {
63+
firstLocalDeviceSerinum = it.serialNumber
64+
return@loop
65+
}
6566
}
6667
}
67-
6868
if (firstLocalDeviceSerinum.isNullOrEmpty().not()) {
69+
6970
project.exec {
70-
it.commandLine(adb,
71-
"-s",
72-
firstLocalDeviceSerinum,
73-
"install",
74-
"-r",
75-
FileUtil.getApkLocalPath())
71+
it.commandLine(adb, "-s", firstLocalDeviceSerinum, "install", "-r", FileUtil.getApkLocalPath())
7672
}
73+
// adb -s <ip:port> install -r <app.apk>
74+
// adb -s <ip:port> shell monkey -p <包名> -c android.intent.category.LAUNCHER 1
7775
project.exec {
78-
it.commandLine(adb,
79-
"shell",
80-
"monkey",
81-
"-p",
82-
android.defaultConfig.applicationId,
83-
"-c",
84-
"android.intent.category.LAUNCHER",
85-
"1")
76+
it.commandLine(adb, "-s", firstLocalDeviceSerinum, "shell", "monkey", "-p", android.defaultConfig.applicationId, "-c", "android.intent.category.LAUNCHER", "1")
8677
}
8778
}
8879
} catch (e: Exception) {

buildSrc/src/main/kotlin/plugin/utils/PluginUtil.kt

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package plugin.utils
22

3+
import com.android.build.gradle.AppExtension
34
import org.gradle.api.Project
45
import plugin.RocketXPlugin
56
import java.io.File
@@ -35,8 +36,7 @@ fun isRunAssembleTask(curProject: Project): Boolean {
3536

3637

3738
fun isEnable(curProject: Project): Boolean {
38-
val enableFile =
39-
File(curProject.rootProject.rootDir.absolutePath + File.separator + ".gradle" + File.separator + "rocketXEnable")
39+
val enableFile = File(curProject.rootProject.rootDir.absolutePath + File.separator + ".gradle" + File.separator + "rocketXEnable")
4040
return enableFile.exists()
4141
}
4242

@@ -50,8 +50,7 @@ fun getFlavorBuildType(appProject: Project): String {
5050
flavorBuildType = arg.substring(index, arg.length)
5151
}
5252
if (flavorBuildType.isNotEmpty()) {
53-
flavorBuildType =
54-
flavorBuildType.substring(0, 1).toLowerCase(Locale.ROOT) + flavorBuildType.substring(1)
53+
flavorBuildType = flavorBuildType.substring(0, 1).toLowerCase(Locale.ROOT) + flavorBuildType.substring(1)
5554
}
5655
return flavorBuildType
5756
}
@@ -81,4 +80,57 @@ fun isCurProjectRun(appProject: Project): Boolean {
8180

8281

8382
return ret
83+
}
84+
85+
86+
fun boostGradleOption(appProject: Project) {
87+
//并行运行task
88+
89+
if (!appProject.hasProperty("org.gradle.daemon")) {
90+
appProject.rootProject.extensions.extraProperties.set("org.gradle.daemon", "true")
91+
}
92+
if (!appProject.hasProperty("kotlin.incremental")) {
93+
appProject.rootProject.extensions.extraProperties.set("kotlin.incremental", true)
94+
}
95+
if (!appProject.hasProperty("kotlin.incremental.java")) {
96+
appProject.rootProject.extensions.extraProperties.set("kotlin.incremental.java", "true")
97+
}
98+
if (!appProject.hasProperty("kotlin.incremental.js")) {
99+
appProject.rootProject.extensions.extraProperties.set("kotlin.incremental.js", "true")
100+
}
101+
if (!appProject.hasProperty("kotlin.caching.enabled")) {
102+
appProject.rootProject.extensions.extraProperties.set("kotlin.caching.enabled", "true")
103+
}
104+
105+
if (!appProject.hasProperty("org.gradle.parallel")) {
106+
appProject.rootProject.extensions.extraProperties.set("org.gradle.parallel", "true")
107+
}
108+
if (!appProject.hasProperty("kotlin.parallel.tasks.in.project")) {
109+
appProject.rootProject.extensions.extraProperties.set("kotlin.parallel.tasks.in.project", "true")
110+
}
111+
if (!appProject.hasProperty("kapt.use.worker.api")) {
112+
appProject.rootProject.extensions.extraProperties.set("kapt.use.worker.api", "true")
113+
}
114+
if (!appProject.hasProperty("kapt.incremental.apt")) {
115+
appProject.rootProject.extensions.extraProperties.set("kapt.incremental.apt", "true")
116+
}
117+
if (!appProject.hasProperty("kapt.classloaders.cache.size")) {
118+
appProject.rootProject.extensions.extraProperties.set("kapt.classloaders.cache.size", "5")
119+
}
120+
if (!appProject.hasProperty("kapt.include.compile.classpath")) {
121+
appProject.rootProject.extensions.extraProperties.set("kapt.include.compile.classpath", "false")
122+
}
123+
if (!appProject.hasProperty("org.gradle.caching")) {
124+
appProject.rootProject.extensions.extraProperties.set("org.gradle.caching", "true")
125+
}
126+
if (!appProject.hasProperty("android.enableBuildCache")) {
127+
appProject.rootProject.extensions.extraProperties.set("android.enableBuildCache", "true")
128+
}
129+
130+
appProject.gradle.startParameter.isParallelProjectExecutionEnabled = true
131+
appProject.gradle.startParameter.maxWorkerCount += 4
132+
var android = appProject.extensions.getByType(AppExtension::class.java)
133+
android.aaptOptions.cruncherEnabled = false
134+
android.aaptOptions.cruncherProcesses = 0
135+
84136
}

maven-publish.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apply plugin: 'signing'
77
def artifact = 'rocketx'
88
def libraryName = 'videoprogressview-sdk'
99
def libraryDescription = 'speed build plugin'
10-
def libraryVersion = '1.0.18'
10+
def libraryVersion = '1.0.19'
1111

1212
def publishedGroupId='io.github.trycatchx'
1313
def siteUrl='https://github.com/trycatchx/RocketXPlugin'

projectC/src/main/java/com/projectc/MainActivityC.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class MainActivityC : AppCompatActivity() {
1010
companion object {
1111
fun test() {
1212
Log.e("lzy", "test: 1111")
13+
Log.e("lzy", "test: 1111")
1314
}
1415
}
1516

@@ -19,6 +20,5 @@ class MainActivityC : AppCompatActivity() {
1920

2021
val mBinding = ActivityProjectcBinding.inflate(getLayoutInflater())
2122
setContentView(mBinding.getRoot())
22-
println("sf")
2323
}
2424
}

0 commit comments

Comments
 (0)