Chore: 切换 clash 内核到自有仓库并补全本地构建

- .gitmodules: clash-foss 指向 tongtongstudio/Dreamacro_clash,premium 条目注释保留

- 移除 premium gitlink,premium 变体仍由 variantFilter 自动跳过

- 新增 scripts/build-clash-core.ps1,本地构建 4 个 ABI 的 libclash.so

- kaidl 改用本地 mavenLocal 的 1.15;CMake 传入 GO_OUTPUT 并通过 jniLibs 打包 libclash.so
This commit is contained in:
tongtong committed 2026-11-26 13:31:55 +08:00
1 parent 8506303693
commit dce9562944
10 files changed
+166 -39

No files matched your search

+5 -4
View File
@@ -1,6 +1,7 @@
[submodule "clash-foss"]
path = core/src/foss/golang/clash
url = https://github.com/Kr328/clash.git
[submodule "clash-premium"]
path = core/src/premium/golang/clash
url = https://github.com/Kr328/clash.git
url = https://github.com/tongtongstudio/Dreamacro_clash.git
# clash-premium: Kr328/clash premium 分支已删除,暂不提供源码(构建时 premium 变体会自动跳过)
# [submodule "clash-premium"]
# path = core/src/premium/golang/clash
# url = https://github.com/Kr328/clash.git
+3 -3
View File
@@ -1,12 +1,12 @@
## Clash for Android
A Graphical user interface of [clash](https://github.com/Dreamacro/clash) for Android
A Graphical user interface of [clash](https://github.com/tongtongstudio/Dreamacro_clash) for Android
<a href="https://play.google.com/store/apps/details?id=com.github.kr328.clash"><img width="200px" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png"/></a> or [Releases](https://github.com/Kr328/ClashForAndroid/releases)
<a href="https://play.google.com/store/apps/details?id=com.github.kr328.clash"><img width="200px" alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png"/></a> or [Releases](https://github.com/tongtongstudio/ClashForAndroid/releases)
### Feature
Fully feature of [clash](https://github.com/Dreamacro/clash) ~~(Exclude `external-controller`~~
Fully feature of [clash](https://github.com/tongtongstudio/Dreamacro_clash) ~~(Exclude `external-controller`~~
### Requirement
+19 -5
View File
@@ -7,24 +7,38 @@ import java.util.*
buildscript {
repositories {
mavenCentral()
mavenLocal()
// mavenCentral()
google()
maven("https://maven.kr328.app/releases")
// maven("https://maven.kr328.app/releases")
maven("https://jitpack.io")
maven("https://developer.huawei.com/repo/")
maven("https://maven.aliyun.com/repository/central")
maven("https://maven.aliyun.com/repository/jcenter")
maven("https://maven.aliyun.com/repository/public")
maven("https://maven.aliyun.com/repository/google")
}
dependencies {
classpath(libs.build.android)
classpath(libs.build.kotlin.common)
classpath(libs.build.kotlin.serialization)
classpath(libs.build.ksp)
classpath(libs.build.golang)
// classpath(libs.build.golang)
}
}
subprojects {
repositories {
mavenCentral()
mavenLocal()
// mavenCentral()
google()
maven("https://maven.kr328.app/releases")
// maven("https://maven.kr328.app/releases")
maven("https://jitpack.io")
maven("https://developer.huawei.com/repo/")
maven("https://maven.aliyun.com/repository/central")
maven("https://maven.aliyun.com/repository/jcenter")
maven("https://maven.aliyun.com/repository/public")
maven("https://maven.aliyun.com/repository/google")
}
val isApp = name == "app"
+30 -23
View File
@@ -1,5 +1,5 @@
import com.github.kr328.golang.GolangBuildTask
import com.github.kr328.golang.GolangPlugin
//import com.github.kr328.golang.GolangBuildTask
//import com.github.kr328.golang.GolangPlugin
import java.io.FileOutputStream
import java.net.URL
import java.time.Duration
@@ -8,7 +8,7 @@ plugins {
kotlin("android")
id("com.android.library")
id("kotlinx-serialization")
id("golang-android")
// id("golang-android")
}
val geoipDatabaseUrl =
@@ -17,22 +17,22 @@ val geoipInvalidate = Duration.ofDays(7)!!
val geoipOutput = buildDir.resolve("intermediates/golang_blob")
val golangSource = file("src/main/golang/native")
golang {
sourceSets {
create("foss") {
tags.set(listOf("foss"))
srcDir.set(file("src/foss/golang"))
}
create("premium") {
tags.set(listOf("premium", "without_gvisor", "without_system"))
srcDir.set(file("src/premium/golang"))
}
all {
fileName.set("libclash.so")
packageName.set("cfa/native")
}
}
}
//golang {
// sourceSets {
// create("foss") {
// tags.set(listOf("foss"))
// srcDir.set(file("src/foss/golang"))
// }
// create("premium") {
// tags.set(listOf("premium", "without_gvisor", "without_system"))
// srcDir.set(file("src/premium/golang"))
// }
// all {
// fileName.set("libclash.so")
// packageName.set("cfa/native")
// }
// }
//}
android {
productFlavors {
@@ -40,7 +40,7 @@ android {
externalNativeBuild {
cmake {
arguments("-DGO_SOURCE:STRING=${golangSource}")
arguments("-DGO_OUTPUT:STRING=${GolangPlugin.outputDirOf(project, null, null)}")
arguments("-DGO_OUTPUT:STRING=${rootProject.buildDir}/golang")
arguments("-DFLAVOR_NAME:STRING=$name")
}
}
@@ -52,6 +52,13 @@ android {
path = file("src/main/cpp/CMakeLists.txt")
}
}
sourceSets {
getByName("main") {
// 手动构建的 libclash.so 通过 jniLibs 打包进 APK(原 golang 插件被禁用后需手工提供)
jniLibs.srcDir(rootProject.buildDir.resolve("golang/fossDebug"))
}
}
}
dependencies {
@@ -63,9 +70,9 @@ dependencies {
}
afterEvaluate {
tasks.withType(GolangBuildTask::class.java).forEach {
it.inputs.dir(golangSource)
}
// tasks.withType(GolangBuildTask::class.java).forEach {
// it.inputs.dir(golangSource)
// }
}
task("downloadGeoipDatabase") {
+1
View File
@@ -7,6 +7,7 @@ require cfa v0.0.0
require (
cfa/blob v0.0.0 // indirect
github.com/Dreamacro/clash v1.7.1 // indirect
github.com/Dreamacro/go-shadowsocks2 v0.1.8 // indirect
github.com/Kr328/tun2socket v0.0.0-20220414050025-d07c78d06d34 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
+2
View File
@@ -1,3 +1,5 @@
github.com/Dreamacro/go-shadowsocks2 v0.1.8 h1:Ixejp5JscEc866gAvm/l6TFd7BOBvDviKgwb1quWw3g=
github.com/Dreamacro/go-shadowsocks2 v0.1.8/go.mod h1:51y4Q6tJoCE7e8TmYXcQRqfoxPfE9Cvn79V6pB6Df7Y=
github.com/Kr328/tun2socket v0.0.0-20220414050025-d07c78d06d34 h1:USCTqih5d1bUXUxWNS9ZD5Tx/lb0jXHEtRIIx/F9dMc=
github.com/Kr328/tun2socket v0.0.0-20220414050025-d07c78d06d34/go.mod h1:YR9wK13TgI5ww8iKWm91MHiSoHC7Oz0U4beCCmtXqLw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+103
View File
@@ -0,0 +1,103 @@
# 为 ClashForAndroid 构建 Go 内核 libclash.so(4 个 ABI)
# 用法: pwsh scripts/build-clash-core.ps1 [-Flavor foss] [-BuildType Debug]
param(
[ValidateSet('foss', 'premium')]
[string]$Flavor = 'foss',
[ValidateSet('Debug', 'Release')]
[string]$BuildType = 'Debug',
[string]$NdkVersion = '23.0.7599858'
)
$ErrorActionPreference = 'Stop'
$ProjectRoot = Split-Path -Parent $PSScriptRoot
$CoreDir = Join-Path $ProjectRoot 'core'
$ModuleDir = Join-Path $CoreDir "src\$Flavor\golang"
$OutputDir = Join-Path $ProjectRoot "build\golang\$Flavor$BuildType"
if (-not (Test-Path (Join-Path $ModuleDir 'clash\go.mod'))) {
throw "未找到 $Flavor 内核源码: $ModuleDir\clash"
}
# 从 local.properties 读取 sdk.dir(形如 F\:\\AndroidSDK)
$sdkDir = $env:ANDROID_SDK_ROOT
$localProps = Join-Path $ProjectRoot 'local.properties'
if (-not $sdkDir -and (Test-Path $localProps)) {
$match = Select-String -Path $localProps -Pattern '^sdk\.dir=(.+)$' | Select-Object -First 1
if ($match) { $sdkDir = $match.Matches[0].Groups[1].Value.Replace('\:', ':').Replace('\\', '\') }
}
if (-not $sdkDir) { throw '未找到 Android SDK,请设置 ANDROID_SDK_ROOT 或在 local.properties 配置 sdk.dir' }
$NdkDir = Join-Path $sdkDir "ndk\$NdkVersion"
$ToolchainDir = Join-Path $NdkDir 'toolchains\llvm\prebuilt\windows-x86_64'
if (-not (Test-Path (Join-Path $ToolchainDir 'bin\clang.exe'))) {
throw "未找到 NDK ${NdkVersion}: $NdkDir"
}
# geoip blob 模块(cfa/blob)
$BlobDir = Join-Path $CoreDir 'build\intermediates\golang_blob'
New-Item -ItemType Directory -Force $BlobDir | Out-Null
$BlobMod = Join-Path $BlobDir 'go.mod'
$BlobSrc = Join-Path $BlobDir 'blob.go'
$BlobMmdb = Join-Path $BlobDir 'Country.mmdb'
if (-not (Test-Path $BlobMod)) { Set-Content -Path $BlobMod -Value 'module "cfa/blob"' -Encoding utf8NoBOM }
if (-not (Test-Path $BlobSrc)) {
Set-Content -Path $BlobSrc -Encoding utf8NoBOM -Value @(
'package blob',
'',
'import _ "embed"',
'',
'//go:embed Country.mmdb',
'var GeoipDatabase []byte'
)
}
if (-not (Test-Path $BlobMmdb)) {
Write-Host '下载 Country.mmdb ...'
Invoke-WebRequest -UseBasicParsing 'https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb' -OutFile $BlobMmdb
}
# Go 1.23+ 对旧版 x/net 的 syscall linkname 有检查,需要关闭
$goVersion = (& go env GOVERSION).Trim()
$goMinor = if ($goVersion -match '^go1\.(\d+)') { [int]$Matches[1] } else { 0 }
$checkLinkname = $goMinor -ge 23
$tags = if ($Flavor -eq 'premium') { 'premium,without_gvisor,without_system' } else { 'foss' }
$targets = @(
@{ Abi = 'arm64-v8a'; Arch = 'arm64'; GoArm = $null; Triple = 'aarch64-linux-android21' },
@{ Abi = 'armeabi-v7a'; Arch = 'arm'; GoArm = '7'; Triple = 'armv7a-linux-androideabi21' },
@{ Abi = 'x86'; Arch = '386'; GoArm = $null; Triple = 'i686-linux-android21' },
@{ Abi = 'x86_64'; Arch = 'amd64'; GoArm = $null; Triple = 'x86_64-linux-android21' }
)
$env:GOOS = 'android'
$env:CGO_ENABLED = '1'
$env:CC = Join-Path $ToolchainDir 'bin\clang.exe'
$env:GOFLAGS = '-mod=mod'
# 允许 --target/--sysroot 等 NDK 交叉编译参数通过 Go 的 cgo flag 校验
$env:CGO_CFLAGS_ALLOW = '.*'
$env:CGO_LDFLAGS_ALLOW = '.*'
foreach ($t in $targets) {
$abiDir = Join-Path $OutputDir $t.Abi
New-Item -ItemType Directory -Force $abiDir | Out-Null
$env:GOARCH = $t.Arch
if ($t.GoArm) { $env:GOARM = $t.GoArm } else { Remove-Item Env:GOARM -ErrorAction SilentlyContinue }
$env:CGO_CFLAGS = "--target=$($t.Triple) --gcc-toolchain=$ToolchainDir --sysroot=$ToolchainDir/sysroot"
$env:CGO_LDFLAGS = $env:CGO_CFLAGS
$args = @('build', '-tags', $tags, '-buildmode=c-shared')
if ($checkLinkname) { $args += '-ldflags=-checklinkname=0' }
$args += @('-o', (Join-Path $abiDir 'libclash.so'), 'cfa/native')
Write-Host "构建 $Flavor/$($t.Abi) ..."
Push-Location $ModuleDir
try {
& go @args
if ($LASTEXITCODE -ne 0) { throw "go build 失败: $Flavor/$($t.Abi)" }
} finally {
Pop-Location
}
}
Write-Host "完成: $OutputDir"
Get-ChildItem -Recurse -File $OutputDir | Select-Object FullName, Length
+2 -2
View File
@@ -32,7 +32,7 @@ dependencyResolutionManagement {
val viewpager = "1.0.0"
val material = "1.6.1"
val serialization = "1.3.3"
val kaidl = "1.15"
val kaidl = "1.15" // 本地 mavenLocal 发布(源码 D:\TongTongStudio\deprecated\kaidl)
val room = "2.4.2"
val multiprocess = "1.0.0"
@@ -40,7 +40,7 @@ dependencyResolutionManagement {
library("build-kotlin-common", "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin")
library("build-kotlin-serialization", "org.jetbrains.kotlin:kotlin-serialization:$kotlin")
library("build-ksp", "com.google.devtools.ksp:symbol-processing-gradle-plugin:$ksp")
library("build-golang", "com.github.kr328.golang:gradle-plugin:$golang")
// library("build-golang", "com.github.kr328.golang:gradle-plugin:$golang")
library("kotlin-coroutine", "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine")
library("kotlin-serialization-json", "org.jetbrains.kotlinx:kotlinx-serialization-json:$serialization")
library("androidx-core", "androidx.core:core-ktx:$coreKtx")