diff --git a/buildSrc/src/main/java/com/github/kr328/clash/tools/BuildConfig.kt b/buildSrc/src/main/java/com/github/kr328/clash/tools/BuildConfig.kt index 24acc5de..020cd442 100644 --- a/buildSrc/src/main/java/com/github/kr328/clash/tools/BuildConfig.kt +++ b/buildSrc/src/main/java/com/github/kr328/clash/tools/BuildConfig.kt @@ -11,14 +11,12 @@ data class BuildConfig( val minSdkVersion: Int, ) : Serializable { companion object { - fun of(extension: BaseExtension, variant: BaseVariant): BuildConfig { + fun of(abis: List, minSdkVersion: Int, variant: BaseVariant): BuildConfig { return BuildConfig( debug = variant.buildType.isDebuggable, premium = variant.flavorName == "premium", - abis = extension.defaultConfig.externalNativeBuild.cmake.abiFilters - .map { NativeAbi.parse(it) } - .distinct(), - minSdkVersion = extension.defaultConfig.minSdkVersion!!.apiLevel + abis = abis, + minSdkVersion = minSdkVersion ) } } diff --git a/buildSrc/src/main/java/com/github/kr328/clash/tools/ClashBuildPlugin.kt b/buildSrc/src/main/java/com/github/kr328/clash/tools/ClashBuildPlugin.kt index 436d381c..2bc69df9 100644 --- a/buildSrc/src/main/java/com/github/kr328/clash/tools/ClashBuildPlugin.kt +++ b/buildSrc/src/main/java/com/github/kr328/clash/tools/ClashBuildPlugin.kt @@ -11,8 +11,19 @@ class ClashBuildPlugin : Plugin { override fun apply(target: Project) { target.afterEvaluate { target.extensions.getByType(LibraryExtension::class.java).apply { + val abis = defaultConfig.externalNativeBuild.cmake.abiFilters + .map { NativeAbi.parse(it) } + .distinct() + val minSdkVersion = defaultConfig.minSdkVersion!!.apiLevel + + target.tasks.register("cleanGolang", ClashCleanTask::class.java) { + it.applyFrom(target, abis) + + target.tasks.getByName("clean").dependsOn(it) + } + libraryVariants.forEach { variant -> - val config = BuildConfig.of(this, variant) + val config = BuildConfig.of(abis, minSdkVersion, variant) val buildDir = target.golangBuild.resolve(variant.name) val capitalize = variant.name.capitalize(Locale.getDefault()) diff --git a/buildSrc/src/main/java/com/github/kr328/clash/tools/ClashCleanTask.kt b/buildSrc/src/main/java/com/github/kr328/clash/tools/ClashCleanTask.kt new file mode 100644 index 00000000..e4451bed --- /dev/null +++ b/buildSrc/src/main/java/com/github/kr328/clash/tools/ClashCleanTask.kt @@ -0,0 +1,17 @@ +package com.github.kr328.clash.tools + +import org.gradle.api.Project +import org.gradle.api.tasks.Delete +import golangSource + +abstract class ClashCleanTask : Delete() { + fun applyFrom(project: Project, abis: List) { + val bridge = project.golangSource.resolve("tun2socket/bridge") + + delete(bridge.resolve("build")) + + abis.forEach { + delete(bridge.resolve("build_android_${it.goArch}.go")) + } + } +} \ No newline at end of file