Skip to content

Commit 5e789a0

Browse files
committed
Refactor gradle ensure tasks
1 parent 89837d1 commit 5e789a0

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

.github/workflows/android-app.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
uses: actions/cache@v4
115115
id: cache-relay-list
116116
with:
117-
path: build/relays.json
117+
path: android/app/build/extraAssets/relays.json
118118
key: relay-list-${{ steps.get-date.outputs.date }}
119119

120120
- name: Checkout repository
@@ -128,14 +128,14 @@ jobs:
128128
env:
129129
RUSTFLAGS: --deny warnings
130130
run: |
131-
mkdir -p build
132-
cargo run --bin relay_list > build/relays.json
131+
mkdir -p android/app/build/extraAssets
132+
cargo run --bin relay_list > android/app/build/extraAssets/relays.json
133133
134134
- name: Upload
135135
uses: actions/upload-artifact@v4
136136
with:
137137
name: relay-list
138-
path: build/relays.json
138+
path: android/app/build/extraAssets/relays.json
139139
if-no-files-found: error
140140
retention-days: 7
141141

@@ -313,7 +313,6 @@ jobs:
313313
- uses: actions/download-artifact@v4
314314
with:
315315
name: relay-list
316-
path: build
317316

318317
- name: Build app
319318
uses: burrunan/gradle-cache-action@v1

android/app/build.gradle.kts

+15-18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ plugins {
1919

2020
val repoRootPath = rootProject.projectDir.absoluteFile.parentFile.absolutePath
2121
val extraAssetsDirectory = "${project.buildDir}/extraAssets"
22+
val relayListPath = "$extraAssetsDirectory/relays.json"
2223
val defaultChangelogAssetsDirectory = "$repoRootPath/android/src/main/play/release-notes/"
2324
val extraJniDirectory = "${project.buildDir}/extraJni"
2425

@@ -146,10 +147,6 @@ android {
146147
)
147148
}
148149

149-
tasks.withType<MergeSourceSetFolders> { dependsOn(getTasksByName("copyExtraAssets", true)) }
150-
151-
tasks.withType<LintModelWriterTask> { dependsOn(getTasksByName("copyExtraAssets", true)) }
152-
153150
// Suppressing since we don't seem have much of an option than using this api. The impact should
154151
// also be limited to tests.
155152
@Suppress("UnstableApiUsage")
@@ -238,10 +235,14 @@ android {
238235
}
239236

240237
createDistBundle.dependsOn("bundle$capitalizedVariantName")
241-
}
242238

243-
project.tasks.assemble.dependsOn("ensureJniDirectoryExist")
244-
project.tasks.assemble.dependsOn("ensureValidVersionCode")
239+
// Ensure all relevant assemble tasks depend on our ensure tasks.
240+
tasks.get("assemble$capitalizedVariantName").apply {
241+
dependsOn(tasks.get("ensureRelayListExist"))
242+
dependsOn(tasks.get("ensureJniDirectoryExist"))
243+
dependsOn(tasks.get("ensureValidVersionCode"))
244+
}
245+
}
245246
}
246247

247248
junitPlatform {
@@ -274,14 +275,16 @@ configure<org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension> {
274275
skipConfigurations = listOf("lintClassPath")
275276
}
276277

277-
tasks.register("copyExtraAssets", Copy::class) {
278-
from("$repoRootPath/build")
279-
include("relays.json")
280-
into(extraAssetsDirectory)
278+
tasks.register("ensureRelayListExist") {
279+
doLast {
280+
if (!file(relayListPath).exists()) {
281+
throw GradleException("Missing relay list: $relayListPath")
282+
}
283+
}
281284
}
282285

283286
tasks.register("ensureJniDirectoryExist") {
284-
doFirst {
287+
doLast {
285288
if (!file(extraJniDirectory).exists()) {
286289
throw GradleException("Missing JNI directory: $extraJniDirectory")
287290
}
@@ -306,12 +309,6 @@ tasks.create("printVersion") {
306309
}
307310
}
308311

309-
afterEvaluate {
310-
tasks.withType(com.android.build.gradle.internal.lint.AndroidLintAnalysisTask::class.java) {
311-
mustRunAfter(tasks.getByName("copyExtraAssets"))
312-
}
313-
}
314-
315312
play { serviceAccountCredentials.set(file("play-api-key.json")) }
316313

317314
dependencies {

build-apk.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ else
7373
fi
7474

7575
$GRADLE_CMD --console plain clean
76+
mkdir -p "app/build/extraAssets"
7677
mkdir -p "app/build/extraJni"
7778
popd
7879

@@ -111,7 +112,7 @@ for ARCHITECTURE in ${ARCHITECTURES:-aarch64 armv7 x86_64 i686}; do
111112
done
112113

113114
echo "Updating relays.json..."
114-
cargo run --bin relay_list "${CARGO_ARGS[@]}" > build/relays.json
115+
cargo run --bin relay_list "${CARGO_ARGS[@]}" > android/build/extraAssets/relays.json
115116

116117
cd "$SCRIPT_DIR/android"
117118
$GRADLE_CMD --console plain "${GRADLE_TASKS[@]}"

0 commit comments

Comments
 (0)