Skip to content

Commit

Permalink
Refactor: refactor project structure & update clash core (#1174)
Browse files Browse the repository at this point in the history
* Refactor: refactor project structure

* Chore: remove apply

* Chore: update clash core

* Fix: fix versionName & versionCode patch

* Chore: update golang plugin

* Fix: fix workflow build
  • Loading branch information
Kr328 authored Sep 11, 2021
1 parent fa23be7 commit 11c4e19
Show file tree
Hide file tree
Showing 78 changed files with 542 additions and 939 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/build-unsigned.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Build Unsigned
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '.github/**'
- '.idea/**'
Expand All @@ -13,8 +10,6 @@ on:
- 'LICENSE'
- 'NOTICE'
pull_request:
branches:
- main
paths-ignore:
- '.github/**'
- '.idea/**'
Expand All @@ -38,10 +33,8 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17
- name: Setup Android SDK
uses: android-actions/setup-android@v2
- name: Setup Cmake & Ninja
uses: lukka/get-cmake@latest
- name: Build
run: ./gradlew --no-daemon app:assembleRelease
run: ./gradlew --no-daemon app:assembleFossRelease
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ gradle-app.setting
# Ignore IDEA config
*.iml
/.idea/*
/core/src/main/golang/.idea/*
!/.idea/codeStyles
!/core/src/main/golang/.idea/codeStyles
/core/src/foss/go/.idea/*
!/core/src/foss/go/.idea/codeStyles
/core/src/premium/go/.idea/*
!/core/src/premium/go/.idea/codeStyles

# KeyStore
*.keystore
Expand Down
10 changes: 2 additions & 8 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[submodule "core/src/main/golang/clash"]
path = core/src/main/golang/clash
[submodule "clash-foss"]
path = core/src/foss/go/clash
url = https://github.com/Kr328/clash.git
[submodule "kaidl"]
path = kaidl
url = https://github.com/Kr328/kaidl.git
[submodule "core/src/main/golang/tun2socket"]
path = core/src/main/golang/tun2socket
url = https://github.com/Kr328/tun2socket-lwip.git
149 changes: 18 additions & 131 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,144 +1,31 @@
import java.util.*

plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
}

android {
compileSdk = buildTargetSdkVersion

flavorDimensions(buildFlavor)

defaultConfig {
applicationId = "com.github.kr328.clash"

minSdk = buildMinSdkVersion
targetSdk = buildTargetSdkVersion

versionCode = buildVersionCode
versionName = buildVersionName

resConfigs("zh-rCN", "zh-rHK", "zh-rTW")

resValue("string", "release_name", "v$buildVersionName")
resValue("integer", "release_code", "$buildVersionCode")
}

packagingOptions {
exclude("DebugProbesKt.bin")
}

buildTypes {
named("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

productFlavors {
create("foss") {
dimension = "foss"
versionNameSuffix = ".foss"
applicationIdSuffix = ".foss"
}
create("premium") {
dimension = "premium"
versionNameSuffix = ".premium"

if (buildFlavor == "premium") {
val localFile = rootProject.file("local.properties")
if (localFile.exists()) {
val appCenterKey = localFile.inputStream()
.use { Properties().apply { load(it) } }
.getProperty("appcenter.key", null)

if (appCenterKey != null) {
buildConfigField("String", "APP_CENTER_KEY", "\"$appCenterKey\"")
} else {
buildConfigField("String", "APP_CENTER_KEY", "null")
}
} else {
buildConfigField("String", "APP_CENTER_KEY", "null")
}
}
}
}

val signingFile = rootProject.file("keystore.properties")
if (signingFile.exists()) {
val properties = Properties().apply {
signingFile.inputStream().use {
load(it)
}
}
signingConfigs {
create("release") {
storeFile = rootProject.file(properties.getProperty("storeFile")!!)
storePassword = properties.getProperty("storePassword")!!
keyAlias = properties.getProperty("keyAlias")!!
keyPassword = properties.getProperty("keyPassword")!!
}
}
buildTypes {
named("release") {
signingConfig = signingConfigs["release"]
}
}
}

buildFeatures {
dataBinding = true
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

splits {
abi {
isEnable = true
isUniversalApk = true
}
}
id("com.android.application")
}

dependencies {
val premiumImplementation by configurations
implementation(project(":core"))
implementation(project(":service"))
implementation(project(":design"))
implementation(project(":common"))

api(project(":core"))
api(project(":service"))
api(project(":design"))
api(project(":common"))
implementation(kotlin("stdlib-jdk7"))
implementation(deps.kotlin.coroutine)
implementation(deps.androidx.core)
implementation(deps.androidx.activity)
implementation(deps.androidx.fragment)
implementation(deps.androidx.appcompat)
implementation(deps.androidx.coordinator)
implementation(deps.androidx.recyclerview)
implementation(deps.google.material)

premiumImplementation("com.microsoft.appcenter:appcenter-analytics:$appcenterVersion")
premiumImplementation("com.microsoft.appcenter:appcenter-crashes:$appcenterVersion")
val premiumImplementation by configurations

implementation(kotlin("stdlib-jdk7"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion")
implementation("androidx.core:core-ktx:$coreVersion")
implementation("androidx.activity:activity:$activityVersion")
implementation("androidx.appcompat:appcompat:$appcompatVersion")
implementation("androidx.coordinatorlayout:coordinatorlayout:$coordinatorlayoutVersion")
implementation("androidx.recyclerview:recyclerview:$recyclerviewVersion")
implementation("androidx.fragment:fragment:$fragmentVersion")
implementation("com.google.android.material:material:$materialVersion")
premiumImplementation(deps.appcenter.analytics)
premiumImplementation(deps.appcenter.crashes)
}

task("cleanRelease", type = Delete::class) {
tasks.getByName("clean", type = Delete::class) {
delete(file("release"))
}

afterEvaluate {
tasks["clean"].dependsOn(tasks["cleanRelease"])
}
116 changes: 116 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,127 @@
@file:Suppress("UNUSED_VARIABLE")

import com.android.build.gradle.BaseExtension
import java.net.URL

buildscript {
repositories {
mavenCentral()
mavenLocal()
google()
maven("https://maven.kr328.app/releases")
}
dependencies {
classpath(deps.build.android)
classpath(deps.build.kotlin.common)
classpath(deps.build.kotlin.serialization)
classpath(deps.build.ksp)
classpath(deps.build.golang)
}
}

allprojects {
repositories {
google()
mavenCentral()
maven("https://maven.kr328.app/releases")
}
}

subprojects {
val isApp = name == "app"

apply(plugin = if (isApp) "com.android.application" else "com.android.library")

extensions.configure(BaseExtension::class) {
val minSdkVersion = 21
val targetSdkVersion = 30
val buildVersionCode = 204009
val buildVersionName = "2.4.9"
val defaultDimension = "feature"

ndkVersion = "23.0.7599858"

compileSdkVersion(targetSdkVersion)

defaultConfig {
if (isApp) {
applicationId = "com.github.kr328.clash"
}

minSdk = minSdkVersion
targetSdk = targetSdkVersion

versionName = buildVersionName
versionCode = buildVersionCode

if (!isApp) {
consumerProguardFiles("consumer-rules.pro")
}

resValue("string", "release_name", "v$buildVersionName")
resValue("integer", "release_code", "$buildVersionCode")

externalNativeBuild {
cmake {
abiFilters("arm64-v8a", "armeabi-v7a", "x86", "x86_64")
}
}
}

externalNativeBuild {
cmake {
version = "3.18.1"
}
}

if (isApp) {
packagingOptions {
excludes.add("DebugProbesKt.bin")
}
}

buildTypes {
named("release") {
isMinifyEnabled = isApp
isShrinkResources = isApp
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

productFlavors {
flavorDimensions(defaultDimension)

create("foss") {
dimension = defaultDimension
versionNameSuffix = ".foss"

if (isApp) {
applicationIdSuffix = ".foss"
}
}
create("premium") {
dimension = defaultDimension
versionNameSuffix = ".premium"
}
}

buildFeatures.apply {
dataBinding {
isEnabled = name != "hideapi"
}
}

if (isApp) {
splits {
abi {
isEnable = true
isUniversalApk = true
}
}
}
}
}

Expand Down
25 changes: 0 additions & 25 deletions buildSrc/build.gradle.kts

This file was deleted.

17 changes: 0 additions & 17 deletions buildSrc/src/main/java/Build.kt

This file was deleted.

Loading

0 comments on commit 11c4e19

Please sign in to comment.