Skip to content

Commit d3af208

Browse files
authored
Merge pull request #563 from RedrockMobile/guoxiangrui/feature/update_libs
Guoxiangrui/feature/update libs
2 parents 196463d + 908d890 commit d3af208

127 files changed

Lines changed: 909 additions & 777 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/xcode.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build-logic/config/src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object Config {
1515
const val versionName = "6.10.6-alpha" // 线上6.10.5,开发6.10.6-alpha,自己打包 -alpha,内测 -beta
1616

1717
val composeDesktopVersion: String // compose desktop 只能是 x.y.z 形式,不能带 -
18-
get() = versionName.substringBeforeLast("-")
18+
get() = versionName.substringBefore("-")
1919

2020
val releaseAbiFilters = listOf("arm64-v8a")
2121
val debugAbiFilters = listOf("arm64-v8a","x86_64")

build-logic/manager/src/main/kotlin/UsePlugins.kt

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import com.g985892345.provider.plugin.gradle.extensions.KtProviderExtensions
22
import com.google.devtools.ksp.gradle.KspExtension
3+
import de.jensklingenberg.ktorfit.gradle.KtorfitPluginExtension
34
import org.gradle.api.Project
45
import org.gradle.kotlin.dsl.apply
56
import org.gradle.kotlin.dsl.configure
67
import org.gradle.kotlin.dsl.dependencies
8+
import org.gradle.kotlin.dsl.findByType
79
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
810

911

@@ -22,10 +24,14 @@ fun Project.useKtProvider(isNeedKsp: Boolean = !name.startsWith("api")) {
2224
val ktProvider = extensions.getByName("ktProvider") as KtProviderExtensions
2325
kspMultiplatform(ktProvider.ksp)
2426
}
25-
extensions.configure<KotlinMultiplatformExtension> {
27+
// AGP9 后 application 插件不能与 multiplatform 共存
28+
// 所以这里需要先判断 KotlinMultiplatformExtension 是否存在
29+
extensions.findByType(KotlinMultiplatformExtension::class)?.apply {
2630
sourceSets.commonMain.dependencies {
2731
implementation(libsEx.`kmp-ktProvider-api`)
2832
}
33+
} ?: dependencies {
34+
"implementation"(libsEx.`kmp-ktProvider-api`)
2935
}
3036
}
3137

@@ -90,19 +96,29 @@ fun Project.useNetwork() {
9096
}
9197

9298
private fun Project.kspMultiplatform(dependencyNotation: Any) {
99+
val isMultiplatform = extensions.findByType(KotlinMultiplatformExtension::class) != null
93100
dependencies {
94-
"kspAndroid"(dependencyNotation)
95-
if (Multiplatform.enableIOS(project)) {
96-
"kspIosX64"(dependencyNotation)
97-
"kspIosArm64"(dependencyNotation)
98-
"kspIosSimulatorArm64"(dependencyNotation)
99-
}
100-
if (Multiplatform.enableWeb(project)) {
101-
"kspJs"(dependencyNotation)
102-
"kspWasmJs"(dependencyNotation)
103-
}
104-
if (Multiplatform.enableDesktop(project)) {
105-
"kspDesktop"(dependencyNotation)
101+
if (isMultiplatform) {
102+
if (configurations.findByName("kspAndroid") != null) {
103+
"kspAndroid"(dependencyNotation)
104+
}
105+
if (configurations.findByName("kspIosArm64") != null) {
106+
"kspIosArm64"(dependencyNotation)
107+
}
108+
if (configurations.findByName("kspIosSimulatorArm64") != null) {
109+
"kspIosSimulatorArm64"(dependencyNotation)
110+
}
111+
if (configurations.findByName("kspJs") != null) {
112+
"kspJs"(dependencyNotation)
113+
}
114+
if (configurations.findByName("kspWasmJs") != null) {
115+
"kspWasmJs"(dependencyNotation)
116+
}
117+
if (configurations.findByName("kspDesktop") != null) {
118+
"kspDesktop"(dependencyNotation)
119+
}
120+
} else {
121+
"ksp"(dependencyNotation)
106122
}
107123
}
108124
}

build-logic/manager/src/main/kotlin/manager.app.gradle.kts renamed to build-logic/manager/src/main/kotlin/manager.app-android.gradle.kts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2-
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
31
import rule.ModuleNamespaceCheckRule
42

53
plugins {
64
id("com.android.application")
7-
id("kmp.base")
8-
id("kmp.compose")
95
}
106

117
ProjectChecker.config(project) // 项目检查工具
@@ -77,51 +73,3 @@ android {
7773
buildConfig = true
7874
}
7975
}
80-
81-
kotlin {
82-
if (Multiplatform.enableIOS(project)) {
83-
listOf(
84-
iosX64(),
85-
iosArm64(),
86-
iosSimulatorArm64()
87-
).forEach { iosTarget ->
88-
iosTarget.binaries.framework {
89-
baseName = Config.getBaseName(project)
90-
isStatic = true
91-
}
92-
}
93-
}
94-
if (Multiplatform.enableWeb(project)) {
95-
js {
96-
binaries.executable()
97-
}
98-
99-
@OptIn(ExperimentalWasmDsl::class)
100-
wasmJs {
101-
binaries.executable()
102-
}
103-
}
104-
}
105-
106-
if (Multiplatform.enableDesktop(project)) {
107-
compose.desktop {
108-
application {
109-
mainClass = "CyxbsDesktopAppKt"
110-
nativeDistributions {
111-
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
112-
packageName = Config.getApplicationId(project)
113-
packageVersion = Config.composeDesktopVersion
114-
}
115-
buildTypes {
116-
release {
117-
proguard {
118-
isEnabled.set(true)
119-
configurationFiles.from(rootDir.resolve("build-logic")
120-
.resolve("manager")
121-
.resolve("proguard-rules.pro"))
122-
}
123-
}
124-
}
125-
}
126-
}
127-
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
2+
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
3+
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
4+
5+
plugins {
6+
id("kmp.compose")
7+
}
8+
9+
if (Multiplatform.enableIOS(project)) {
10+
kotlin {
11+
listOf(
12+
iosArm64(),
13+
iosSimulatorArm64()
14+
).forEach { iosTarget ->
15+
iosTarget.binaries.framework {
16+
baseName = Config.getBaseName(project)
17+
isStatic = true
18+
}
19+
// 导出部分项目代码让 iOS 进行引用
20+
NativeBuildType.DEFAULT_BUILD_TYPES.forEach { type ->
21+
iosTarget.binaries.getFramework(type).apply {
22+
// 这里导出会导出很多东西,增加头文件体积,慎重选择导出的模块,能写在 pro iosMain 就尽量不导出
23+
// export(projects.)
24+
}
25+
}
26+
}
27+
}
28+
}
29+
30+
31+
if (Multiplatform.enableWeb(project)) {
32+
kotlin {
33+
js {
34+
binaries.executable()
35+
}
36+
37+
@OptIn(ExperimentalWasmDsl::class)
38+
wasmJs {
39+
binaries.executable()
40+
}
41+
}
42+
}
43+
44+
if (Multiplatform.enableDesktop(project)) {
45+
compose.desktop {
46+
application {
47+
mainClass = "CyxbsDesktopAppKt"
48+
nativeDistributions {
49+
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
50+
packageName = Config.getApplicationId(project)
51+
packageVersion = Config.composeDesktopVersion
52+
}
53+
buildTypes {
54+
release {
55+
proguard {
56+
isEnabled.set(true)
57+
configurationFiles.from(rootDir.resolve("build-logic")
58+
.resolve("manager")
59+
.resolve("proguard-rules.pro"))
60+
}
61+
}
62+
}
63+
}
64+
}
65+
}
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
12
import rule.ModuleNamespaceCheckRule
23

34
plugins {
4-
id("com.android.library")
5+
id("com.android.kotlin.multiplatform.library")
56
id("kmp.base")
67
}
78

89
ProjectChecker.config(project) // 项目检查工具
910

10-
android {
11-
namespace = ModuleNamespaceCheckRule.getCorrectNamespace(project)
12-
compileSdk = libsEx.versions.`android-compileSdk`.toInt()
13-
defaultConfig {
11+
kotlin {
12+
android {
13+
namespace = ModuleNamespaceCheckRule.getCorrectNamespace(project)
14+
compileSdk = libsEx.versions.`android-compileSdk`.toInt()
1415
minSdk = libsEx.versions.`android-minSdk`.toInt()
15-
}
16-
compileOptions {
17-
val javaVersion = libsEx.versions.javaTarget
18-
sourceCompatibility = JavaVersion.toVersion(javaVersion)
19-
targetCompatibility = JavaVersion.toVersion(javaVersion)
20-
}
21-
lint {
22-
abortOnError = false // 编译遇到错误不退出,可以一次检查多个错误,并且已执行的 task 下次执行会直接走缓存
23-
targetSdk = libsEx.versions.`android-targetSdk`.toInt()
24-
}
25-
// 命名规范设置,因为多模块相同资源名在打包时会合并,所以必须强制开启
26-
val paths = project.path.split(":").drop(1)
27-
if (paths.size == 1) {
28-
resourcePrefix = project.name.substringAfter("_")
29-
} else if (paths.first().contains("cyxbs-")) {
30-
resourcePrefix = project.name
31-
} else {
32-
resourcePrefix = paths[paths.size - 2] + "_" + paths.last()
33-
}
34-
buildFeatures {
35-
buildConfig = true
16+
compilerOptions {
17+
jvmTarget.set(JvmTarget.fromTarget(libsEx.versions.kotlinJvmTarget))
18+
}
19+
lint {
20+
abortOnError = false // 编译遇到错误不退出,可以一次检查多个错误,并且已执行的 task 下次执行会直接走缓存
21+
targetSdk = libsEx.versions.`android-targetSdk`.toInt()
22+
}
23+
androidResources {
24+
// 是否启动资源取决于是否还存在 androidMain/res 文件
25+
enable = project.projectDir.resolve("src").resolve("androidMain").resolve("res").exists()
26+
// 命名规范设置,因为多模块相同资源名在打包时会合并,所以必须强制开启
27+
val paths = project.path.split(":").drop(1)
28+
if (paths.size == 1) {
29+
resourcePrefix = project.name.substringAfter("_")
30+
} else if (paths.first().contains("cyxbs-")) {
31+
resourcePrefix = project.name
32+
} else {
33+
resourcePrefix = paths[paths.size - 2] + "_" + paths.last()
34+
}
35+
}
3636
}
3737
}

build-logic/plugin/checker/src/main/kotlin/rule/ModuleNamespaceCheckRule.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ object ModuleNamespaceCheckRule : ProjectChecker.ICheckRule {
2828
if (project.name == "lib_common") {
2929
return // lib_common 未迁移,这里特殊处理,不进行检查
3030
}
31+
if (project.path.contains("cyxbs-applications")) {
32+
return // 跳过 cyxbs-applications,一般这里面不会新增模块
33+
}
3134
val sourceSetList = listOf(
3235
"androidMain",
3336
"commonMain",

build-logic/plugin/kmp/src/main/kotlin/kmp.base.gradle.kts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1+
import com.android.build.gradle.api.KotlinMultiplatformAndroidPlugin
12
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
2-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
33

44
plugins {
55
kotlin("multiplatform")
66
id(libsEx.plugins.kotlinSerialization)
7-
id(libsEx.plugins.kotlinAtomicfu)
87
}
98

109
kotlin {
1110

1211
compilerOptions {
13-
optIn.add("kotlin.time.ExperimentalTime") // 抑制 ExperimentalTime 的警告
14-
}
15-
16-
androidTarget {
17-
compilerOptions {
18-
jvmTarget.set(JvmTarget.fromTarget(libsEx.versions.kotlinJvmTarget))
19-
}
12+
optIn.add("kotlin.concurrent.atomics.ExperimentalAtomicApi") // 抑制 ExperimentalAtomicApi 的警告
2013
}
2114
if (Multiplatform.enableDesktop(project)) {
2215
jvm("desktop")
2316
}
2417
if (Multiplatform.enableIOS(project)) {
25-
iosX64()
2618
iosArm64()
2719
iosSimulatorArm64()
2820
}
@@ -57,9 +49,11 @@ kotlin {
5749
// atomicfu 显示依赖解决 strictly 0.23.2 问题 https://github.com/Kotlin/kotlinx-atomicfu/issues/469
5850
implementation(libsEx.`kotlinx-atomicfu`)
5951
}
60-
androidMain.dependencies {
61-
implementation(libsEx.`kotlinx-coroutines-android`)
62-
implementation(libsEx.`androidx-appcompat`)
52+
if (plugins.hasPlugin(KotlinMultiplatformAndroidPlugin::class)) { // 需要确保先引入 android 插件
53+
androidMain.dependencies {
54+
implementation(libsEx.`kotlinx-coroutines-android`)
55+
implementation(libsEx.`androidx-appcompat`)
56+
}
6357
}
6458
// 桌面端
6559
if (Multiplatform.enableDesktop(project)) {
@@ -73,7 +67,6 @@ kotlin {
7367
val iosMain = create("iosMain") {
7468
dependsOn(commonMain.get())
7569
}
76-
iosX64Main { dependsOn(iosMain) }
7770
iosArm64Main { dependsOn(iosMain) }
7871
iosSimulatorArm64Main { dependsOn(iosMain) }
7972
}
@@ -83,7 +76,9 @@ kotlin {
8376
val mobileMain = create("mobileMain") {
8477
dependsOn(commonMain.get())
8578
}
86-
androidMain { dependsOn(mobileMain) }
79+
if (plugins.hasPlugin(KotlinMultiplatformAndroidPlugin::class)) {
80+
androidMain { dependsOn(mobileMain) }
81+
}
8782
if (Multiplatform.enableIOS(project)) {
8883
val iosMain by getting {
8984
dependsOn(mobileMain)
@@ -103,7 +98,9 @@ kotlin {
10398
val noWebMain = create("noWebMain") {
10499
dependsOn(commonMain.get())
105100
}
106-
androidMain { dependsOn(noWebMain) }
101+
if (plugins.hasPlugin(KotlinMultiplatformAndroidPlugin::class)) {
102+
androidMain { dependsOn(noWebMain) }
103+
}
107104
if (Multiplatform.enableIOS(project)) {
108105
iosMain { dependsOn(noWebMain) }
109106
}

0 commit comments

Comments
 (0)