Skip to content

Commit ab52670

Browse files
committed
Improve build system
1 parent e7000d7 commit ab52670

33 files changed

Lines changed: 1286 additions & 3886 deletions

‎app/.gitignore‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,5 @@
55
/x86_64
66
/universal
77
/latestFull
8-
/src/main/java/org/thunderdog/challegram/core/LangUtils.kt
98
/src/main/java/org/drinkmore/ClientException.java
10-
/src/main/res/values/generated.xml
11-
/src/main/java/org/thunderdog/challegram/theme/builtin/Theme*.kt
12-
/src/main/java/org/thunderdog/challegram/theme/ThemeColors.kt
13-
/src/main/java/org/thunderdog/challegram/theme/ThemeProperties.kt
14-
/src/main/java/org/thunderdog/challegram/theme/ThemeId.java
15-
/src/main/java/org/thunderdog/challegram/theme/ColorId.java
16-
/src/main/java/org/thunderdog/challegram/theme/ColorIdTinted.java
17-
/src/main/java/org/thunderdog/challegram/theme/FallbackColorId.kt
18-
/src/main/java/org/thunderdog/challegram/theme/PropertyId.java
19-
/src/main/java/org/thunderdog/challegram/theme/PorterDuffColorId.java
20-
/src/main/java/org/thunderdog/challegram/tool/PorterDuffPaint.kt
219
drafts

‎app/build.gradle.kts‎

Lines changed: 135 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.android.build.api.variant.BuildConfigField
66
import com.android.build.api.variant.impl.VariantOutputImpl
77
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
88
import tgx.gradle.*
9+
import tgx.gradle.source.*
910
import tgx.gradle.task.*
1011
import java.util.*
1112

@@ -16,32 +17,100 @@ plugins {
1617
id("tgx-module")
1718
}
1819

19-
val generateResourcesAndThemes = tasks.register<GenerateResourcesAndThemesTask>("generateResourcesAndThemes") {
20+
val config = tgxConfig.config.get()
21+
val generateBaselineProfile = tgxConfig.generateBaselineProfile.get()
22+
23+
val generateThemes = tasks.register<GenerateThemesTask>("generateThemes") {
2024
group = "Setup"
21-
description = "Generates fresh strings, ids, theme resources and utility methods based on current static files"
25+
description = "Generates fresh ids, theme resources and utility methods based on current theme files"
26+
// Input
27+
colorsAndProperties.set(layout.projectDirectory.file(
28+
"src/main/other/themes/colors-and-properties.xml"
29+
))
30+
themeFiles.from(layout.projectDirectory.dir(
31+
"src/main/other/themes"
32+
).asFileTree.matching {
33+
include("*.tgx-theme")
34+
})
35+
// Output
36+
resOutputDir.set(layout.buildDirectory.dir(
37+
"generated/tgx/themes/res"
38+
))
39+
javaOutputDir.set(layout.buildDirectory.dir(
40+
"generated/tgx/themes/java"
41+
))
42+
kotlinOutputDir.set(layout.buildDirectory.dir(
43+
"generated/tgx/themes/kotlin"
44+
))
2245
}
23-
val updateLanguages = tasks.register<FetchLanguagesTask>("updateLanguages") {
46+
val generateLangFunctions = tasks.register<GenerateLangFunctions>("generateLangFunctions") {
2447
group = "Setup"
25-
description = "Generates and updates all strings.xml resources based on translations.telegram.org"
48+
description = "Generates extra string resources and utility methods based on strings.xml"
49+
// Input
50+
stringsXml.set(layout.projectDirectory.file(
51+
"src/main/res/values/strings.xml"
52+
))
53+
colorIdJava.set(generateThemes.flatMap {
54+
it.javaOutputDir.file(
55+
"org/thunderdog/challegram/theme/ColorId.java"
56+
)
57+
})
58+
propertyIdJava.set(generateThemes.flatMap {
59+
it.javaOutputDir.file(
60+
"org/thunderdog/challegram/theme/PropertyId.java"
61+
)
62+
})
63+
// Output
64+
resOutputDir.set(layout.buildDirectory.dir(
65+
"generated/tgx/strings/res"
66+
))
67+
kotlinOutputDir.set(layout.buildDirectory.dir(
68+
"generated/tgx/strings/kotlin"
69+
))
2670
}
27-
val validateApiTokens = tasks.register<ValidateApiTokensTask>("validateApiTokens") {
71+
val generateEmojiSetsTask = tasks.register<GenerateEmojiSetsTask>("checkEmojiKeyboard") {
2872
group = "Setup"
29-
description = "Validates some API tokens to make sure they work properly and won't cause problems"
73+
description = "Checks that all supported emoji can be entered from the keyboard"
74+
// Input
75+
emojiCode.set(layout.projectDirectory.file(
76+
"src/main/java/org/thunderdog/challegram/tool/EmojiCode.java"
77+
))
78+
emojiCodeColored.set(layout.projectDirectory.file(
79+
"src/main/java/org/thunderdog/challegram/tool/EmojiCodeColored.java"
80+
))
81+
// Output
82+
kotlinOutputDir.set(layout.buildDirectory.dir(
83+
"generated/tgx/emojis/kotlin"
84+
))
3085
}
31-
val updateExceptions = tasks.register<UpdateExceptionsTask>("updateExceptions") {
86+
val generateExceptions = tasks.register<GenerateExceptionsTask>("updateExceptions") {
3287
group = "Setup"
3388
description = "Updates exception class names with the app or TDLib version number in order to have separate group on Google Play Developer Console"
89+
applicationVersion.set(
90+
config.applicationVersion
91+
)
92+
javaOutputDir.set(layout.buildDirectory.dir(
93+
"generated/tgx/exceptions/java"
94+
))
3495
}
35-
val generatePhoneFormat = tasks.register<GeneratePhoneFormatTask>("generatePhoneFormat") {
96+
val validateApiTokens = tasks.register<ValidateApiTokensTask>("validateApiTokens") {
3697
group = "Setup"
37-
description = "Generates utility methods for phone formatting, e.g. +12345678901 -> +1 (234) 567 89-01"
98+
description = "Validates some API tokens to make sure they work properly and won't cause problems"
99+
applicationId.set(
100+
config.applicationId
101+
)
102+
googleServicesJson.set(layout.projectDirectory.file(
103+
"google-services.json"
104+
))
38105
}
39-
val checkEmojiKeyboard = tasks.register<CheckEmojiKeyboardTask>("checkEmojiKeyboard") {
106+
val fetchLocalizedStrings = tasks.register<FetchLocalizedStringsTask>("fetchLocalizedStrings") {
40107
group = "Setup"
41-
description = "Checks that all supported emoji can be entered from the keyboard"
42-
}
108+
description = "Generates and updates all strings.xml resources based on translations.telegram.org"
43109

44-
val config = extra["config"] as ApplicationConfig
110+
resOutputDir.set(layout.buildDirectory.dir(
111+
"generated/tgx/locales/res"
112+
))
113+
}
45114

46115
//noinspection WrongGradleMethod
47116
android {
@@ -83,9 +152,13 @@ android {
83152

84153
defaultConfig {
85154
applicationId = config.applicationId
86-
targetSdk = config.targetSdkVersion
155+
targetSdk = config.build.targetSdkVersion
87156
multiDexEnabled = true
88157

158+
resValue("string", "AppName", config.applicationName)
159+
resValue("string", "account_type", "${config.applicationId}.sync.account")
160+
resValue("string", "content_authority", "${config.applicationId}.sync.provider")
161+
89162
buildConfigString("PROJECT_NAME", config.applicationName)
90163
buildConfigBool("SHARED_STL", Config.SHARED_STL)
91164
buildConfigString("SAFETYNET_API_KEY", config.safetyNetToken)
@@ -105,7 +178,7 @@ android {
105178

106179
buildConfigField("boolean", "EXPERIMENTAL", config.isExperimentalBuild.toString())
107180

108-
buildConfigInt("TARGET_SDK_INT", config.targetSdkVersion)
181+
buildConfigInt("TARGET_SDK_INT", config.build.targetSdkVersion)
109182

110183
buildConfigInt("TELEGRAM_API_ID", config.telegramApiId)
111184
buildConfigString("TELEGRAM_API_HASH", config.telegramApiHash)
@@ -142,7 +215,7 @@ android {
142215

143216
buildConfigString("TDLIB_VERSION", tdlibVersion)
144217

145-
val tgxGitVersionProvider = providers.of(GitVersionValueSource::class) {
218+
val tgxGitVersionProvider = providers.of(GitVersionSource::class) {
146219
parameters.module = layout.projectDirectory
147220
}
148221
val tgxGit = tgxGitVersionProvider.get()
@@ -178,39 +251,39 @@ android {
178251

179252
// OpenSSL version
180253

181-
val openSslGit = providers.of(GitVersionValueSource::class) {
254+
val openSslGit = providers.of(GitVersionSource::class) {
182255
parameters.module = layout.projectDirectory.dir("../tdlib/source/openssl")
183256
}.get()
184257
buildConfigString("OPENSSL_COMMIT", openSslGit.commitHashShort)
185258
buildConfigString("OPENSSL_COMMIT_URL", openSslGit.commitUrl)
186259

187260
// WebRTC version
188261

189-
val webrtcGit = providers.of(GitVersionValueSource::class) {
262+
val webrtcGit = providers.of(GitVersionSource::class) {
190263
parameters.module = layout.projectDirectory.dir("jni/third_party/webrtc")
191264
}.get()
192265
buildConfigString("WEBRTC_COMMIT", webrtcGit.commitHashShort)
193266
buildConfigString("WEBRTC_COMMIT_URL", webrtcGit.commitUrl)
194267

195268
// tgcalls version
196269

197-
val tgcallsGit = providers.of(GitVersionValueSource::class) {
270+
val tgcallsGit = providers.of(GitVersionSource::class) {
198271
parameters.module = layout.projectDirectory.dir("jni/third_party/tgcalls")
199272
}.get()
200273
buildConfigString("TGCALLS_COMMIT", tgcallsGit.commitHashShort)
201274
buildConfigString("TGCALLS_COMMIT_URL", tgcallsGit.commitUrl)
202275

203276
// FFmpeg version
204277

205-
val ffmpegGit = providers.of(GitVersionValueSource::class) {
278+
val ffmpegGit = providers.of(GitVersionSource::class) {
206279
parameters.module = layout.projectDirectory.dir("jni/third_party/ffmpeg")
207280
}.get()
208281
buildConfigString("FFMPEG_COMMIT", ffmpegGit.commitHashShort)
209282
buildConfigString("FFMPEG_COMMIT_URL", ffmpegGit.commitUrl)
210283

211284
// WebP version
212285

213-
val webpGit = providers.of(GitVersionValueSource::class) {
286+
val webpGit = providers.of(GitVersionSource::class) {
214287
parameters.module = layout.projectDirectory.dir("jni/third_party/webp")
215288
}.get()
216289
buildConfigString("WEBP_COMMIT", webpGit.commitHashShort)
@@ -244,6 +317,7 @@ android {
244317

245318
buildFeatures {
246319
buildConfig = true
320+
resValues = true
247321
}
248322

249323
flavorDimensions += arrayOf("SDK", "ABI")
@@ -254,7 +328,7 @@ android {
254328
dimension = "SDK"
255329
isDefault = sdkIndex == Sdk.LATEST
256330

257-
if (config.generateBaselineProfile && variant.flavor != "latest") {
331+
if (generateBaselineProfile && variant.flavor != "latest") {
258332
matchingFallbacks += "latest"
259333
}
260334
Sdk.VARIANTS.forEach { (subSdkIndex, subVariant) ->
@@ -353,17 +427,17 @@ android {
353427
dimension = "ABI"
354428
isDefault = abiIndex == 0
355429

356-
if (config.generateBaselineProfile && !variant.isTestingLab) {
430+
if (generateBaselineProfile && !variant.isTestingLab) {
357431
matchingFallbacks += Abi.VARIANTS[Abi.LAB]!!.flavor
358432
}
359433
Abi.VARIANTS.forEach { (subAbiIndex, subVariant) ->
360434
buildConfigBool("${subVariant.flavor.uppercase()}_FLAVOR", abiIndex == subAbiIndex)
361435
}
362436

363437
ndkVersion = if (variant.is64Bit) {
364-
config.primaryNdkVersion
438+
config.build.primaryNdkVersion
365439
} else {
366-
config.legacyNdkVersion
440+
config.build.legacyNdkVersion
367441
}
368442
// ndkPath = File(sdkDirectory, "ndk/$ndkVersion").absolutePath
369443
buildConfigString("NDK_VERSION", ndkVersion)
@@ -379,10 +453,41 @@ android {
379453

380454
androidComponents {
381455
onVariants(selector().withBuildType("release")) { variant ->
382-
if (config.isExperimentalBuild) {
383-
variant.lifecycleTasks.registerPreBuild(updateLanguages)
384-
} else {
385-
variant.lifecycleTasks.registerPreBuild(updateLanguages, validateApiTokens)
456+
if (!config.isExperimentalBuild) {
457+
variant.lifecycleTasks.registerPreBuild(validateApiTokens)
458+
}
459+
variant.sources.res?.addGeneratedSourceDirectory(
460+
fetchLocalizedStrings, FetchLocalizedStringsTask::resOutputDir
461+
)
462+
}
463+
464+
onVariants { variant ->
465+
variant.sources.res?.apply {
466+
addGeneratedSourceDirectory(
467+
generateThemes, GenerateThemesTask::resOutputDir
468+
)
469+
addGeneratedSourceDirectory(
470+
generateLangFunctions, GenerateLangFunctions::resOutputDir
471+
)
472+
}
473+
variant.sources.java?.apply {
474+
addGeneratedSourceDirectory(
475+
generateThemes, GenerateThemesTask::javaOutputDir
476+
)
477+
addGeneratedSourceDirectory(
478+
generateExceptions, GenerateExceptionsTask::javaOutputDir
479+
)
480+
}
481+
variant.sources.kotlin?.apply {
482+
addGeneratedSourceDirectory(
483+
generateThemes, GenerateThemesTask::kotlinOutputDir
484+
)
485+
addGeneratedSourceDirectory(
486+
generateLangFunctions, GenerateLangFunctions::kotlinOutputDir
487+
)
488+
addGeneratedSourceDirectory(
489+
generateEmojiSetsTask, GenerateEmojiSetsTask::kotlinOutputDir
490+
)
386491
}
387492
}
388493

@@ -397,9 +502,6 @@ android {
397502
sdk * 100 + abi
398503
}
399504
val flavorVersionNameSuffix = StringBuilder().apply {
400-
if (extra.has("app_version_suffix")) {
401-
append(extra["app_version_suffix"])
402-
}
403505
if (config.extension != "none") {
404506
append("-${config.extension}")
405507
}
@@ -409,9 +511,6 @@ android {
409511
if (abiVariant.displayName != "universal" || (config.extension == "none" && sdkVariant.displayName.isNullOrEmpty())) {
410512
append("-${abiVariant.displayName}")
411513
}
412-
if (extra.has("app_name_suffix")) {
413-
append("-${extra["app_name_suffix"]}")
414-
}
415514
if (variant.debuggable) {
416515
append("-debug")
417516
}
@@ -539,16 +638,7 @@ android {
539638
}
540639
}
541640

542-
tasks.preBuild.configure {
543-
dependsOn(
544-
generateResourcesAndThemes,
545-
checkEmojiKeyboard,
546-
generatePhoneFormat,
547-
updateExceptions
548-
)
549-
}
550-
551-
if (config.generateBaselineProfile) {
641+
if (generateBaselineProfile) {
552642
apply(plugin = libs.plugins.androidx.baselineprofile.get().pluginId)
553643

554644
extensions.configure<BaselineProfileConsumerExtension> {

0 commit comments

Comments
 (0)