Skip to content

Commit

Permalink
feat: 默认配置编译加速项
Browse files Browse the repository at this point in the history
  • Loading branch information
chaojiong1zhang20230913 committed Mar 2, 2022
1 parent 0278cba commit 9e6d75d
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 31 deletions.
10 changes: 6 additions & 4 deletions buildSrc/src/main/kotlin/plugin/RocketXPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ open class RocketXPlugin : Plugin<Project> {
}

appProject.gradle.taskGraph.addTaskExecutionListener(object : TaskExecutionListener {
override fun beforeExecute(p0: Task) {
override fun beforeExecute(task: Task) {
if (task.name.contains("Test") || task.name.contains("Lint")) {
task.enabled = false
}
}

override fun afterExecute(task: Task, state: TaskState) {
Expand Down Expand Up @@ -188,9 +191,8 @@ open class RocketXPlugin : Plugin<Project> {
println("transFormList = [\"" + xValue!![0].name + "\"]")
}
}
//并行运行task
appProject.gradle.startParameter.isParallelProjectExecutionEnabled = true
appProject.gradle.startParameter.maxWorkerCount += 4

boostGradleOption(appProject)
}


Expand Down
33 changes: 12 additions & 21 deletions buildSrc/src/main/kotlin/plugin/utils/InstallApkByAdb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class InstallApkByAdb(val appProject: Project) {
fun maybeInstallApkByAdb() {
if (isRunAssembleTask(appProject)) {
val android = appProject.extensions.getByType(AppExtension::class.java)
val installTask =
appProject.tasks.maybeCreate("rocketxInstallTask", InstallApkTask::class.java)
val installTask = appProject.tasks.maybeCreate("rocketxInstallTask", InstallApkTask::class.java)
installTask.android = android
android.applicationVariants.forEach {
getAppAssembleTask(RocketXPlugin.ASSEMBLE + it.flavorName.capitalize() + it.buildType.name.capitalize())?.let { taskProvider ->
Expand Down Expand Up @@ -58,31 +57,23 @@ class InstallApkByAdb(val appProject: Project) {
AndroidDebugBridge.initIfNeeded(false)
val bridge = AndroidDebugBridge.createBridge(android.adbExecutable.path, false)
var firstLocalDeviceSerinum = ""
bridge?.devices?.forEach {
if (!it.serialNumber.isNullOrEmpty()) {
firstLocalDeviceSerinum = it.serialNumber
return@forEach
run loop@{
bridge?.devices?.forEach {
if (!it.serialNumber.isNullOrEmpty()) {
firstLocalDeviceSerinum = it.serialNumber
return@loop
}
}
}

if (firstLocalDeviceSerinum.isNullOrEmpty().not()) {

project.exec {
it.commandLine(adb,
"-s",
firstLocalDeviceSerinum,
"install",
"-r",
FileUtil.getApkLocalPath())
it.commandLine(adb, "-s", firstLocalDeviceSerinum, "install", "-r", FileUtil.getApkLocalPath())
}
// adb -s <ip:port> install -r <app.apk>
// adb -s <ip:port> shell monkey -p <包名> -c android.intent.category.LAUNCHER 1
project.exec {
it.commandLine(adb,
"shell",
"monkey",
"-p",
android.defaultConfig.applicationId,
"-c",
"android.intent.category.LAUNCHER",
"1")
it.commandLine(adb, "-s", firstLocalDeviceSerinum, "shell", "monkey", "-p", android.defaultConfig.applicationId, "-c", "android.intent.category.LAUNCHER", "1")
}
}
} catch (e: Exception) {
Expand Down
60 changes: 56 additions & 4 deletions buildSrc/src/main/kotlin/plugin/utils/PluginUtil.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package plugin.utils

import com.android.build.gradle.AppExtension
import org.gradle.api.Project
import plugin.RocketXPlugin
import java.io.File
Expand Down Expand Up @@ -35,8 +36,7 @@ fun isRunAssembleTask(curProject: Project): Boolean {


fun isEnable(curProject: Project): Boolean {
val enableFile =
File(curProject.rootProject.rootDir.absolutePath + File.separator + ".gradle" + File.separator + "rocketXEnable")
val enableFile = File(curProject.rootProject.rootDir.absolutePath + File.separator + ".gradle" + File.separator + "rocketXEnable")
return enableFile.exists()
}

Expand All @@ -50,8 +50,7 @@ fun getFlavorBuildType(appProject: Project): String {
flavorBuildType = arg.substring(index, arg.length)
}
if (flavorBuildType.isNotEmpty()) {
flavorBuildType =
flavorBuildType.substring(0, 1).toLowerCase(Locale.ROOT) + flavorBuildType.substring(1)
flavorBuildType = flavorBuildType.substring(0, 1).toLowerCase(Locale.ROOT) + flavorBuildType.substring(1)
}
return flavorBuildType
}
Expand Down Expand Up @@ -81,4 +80,57 @@ fun isCurProjectRun(appProject: Project): Boolean {


return ret
}


fun boostGradleOption(appProject: Project) {
//并行运行task

if (!appProject.hasProperty("org.gradle.daemon")) {
appProject.rootProject.extensions.extraProperties.set("org.gradle.daemon", "true")
}
if (!appProject.hasProperty("kotlin.incremental")) {
appProject.rootProject.extensions.extraProperties.set("kotlin.incremental", true)
}
if (!appProject.hasProperty("kotlin.incremental.java")) {
appProject.rootProject.extensions.extraProperties.set("kotlin.incremental.java", "true")
}
if (!appProject.hasProperty("kotlin.incremental.js")) {
appProject.rootProject.extensions.extraProperties.set("kotlin.incremental.js", "true")
}
if (!appProject.hasProperty("kotlin.caching.enabled")) {
appProject.rootProject.extensions.extraProperties.set("kotlin.caching.enabled", "true")
}

if (!appProject.hasProperty("org.gradle.parallel")) {
appProject.rootProject.extensions.extraProperties.set("org.gradle.parallel", "true")
}
if (!appProject.hasProperty("kotlin.parallel.tasks.in.project")) {
appProject.rootProject.extensions.extraProperties.set("kotlin.parallel.tasks.in.project", "true")
}
if (!appProject.hasProperty("kapt.use.worker.api")) {
appProject.rootProject.extensions.extraProperties.set("kapt.use.worker.api", "true")
}
if (!appProject.hasProperty("kapt.incremental.apt")) {
appProject.rootProject.extensions.extraProperties.set("kapt.incremental.apt", "true")
}
if (!appProject.hasProperty("kapt.classloaders.cache.size")) {
appProject.rootProject.extensions.extraProperties.set("kapt.classloaders.cache.size", "5")
}
if (!appProject.hasProperty("kapt.include.compile.classpath")) {
appProject.rootProject.extensions.extraProperties.set("kapt.include.compile.classpath", "false")
}
if (!appProject.hasProperty("org.gradle.caching")) {
appProject.rootProject.extensions.extraProperties.set("org.gradle.caching", "true")
}
if (!appProject.hasProperty("android.enableBuildCache")) {
appProject.rootProject.extensions.extraProperties.set("android.enableBuildCache", "true")
}

appProject.gradle.startParameter.isParallelProjectExecutionEnabled = true
appProject.gradle.startParameter.maxWorkerCount += 4
var android = appProject.extensions.getByType(AppExtension::class.java)
android.aaptOptions.cruncherEnabled = false
android.aaptOptions.cruncherProcesses = 0

}
2 changes: 1 addition & 1 deletion maven-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply plugin: 'signing'
def artifact = 'rocketx'
def libraryName = 'videoprogressview-sdk'
def libraryDescription = 'speed build plugin'
def libraryVersion = '1.0.18'
def libraryVersion = '1.0.19'

def publishedGroupId='io.github.trycatchx'
def siteUrl='https://github.com/trycatchx/RocketXPlugin'
Expand Down
2 changes: 1 addition & 1 deletion projectC/src/main/java/com/projectc/MainActivityC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MainActivityC : AppCompatActivity() {
companion object {
fun test() {
Log.e("lzy", "test: 1111")
Log.e("lzy", "test: 1111")
}
}

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

val mBinding = ActivityProjectcBinding.inflate(getLayoutInflater())
setContentView(mBinding.getRoot())
println("sf")
}
}

0 comments on commit 9e6d75d

Please sign in to comment.