Skip to content

Commit f82c824

Browse files
committed
Refactor lockfile script and gradle tasks
1 parent e804454 commit f82c824

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
lines changed

.github/workflows/android-app.yml

+5-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,7 @@ jobs:
313313
- uses: actions/download-artifact@v4
314314
with:
315315
name: relay-list
316-
path: build
316+
path: android/app/build/extraAssets/relays.json
317317

318318
- name: Build app
319319
uses: burrunan/gradle-cache-action@v1

.github/workflows/android-audit.yml

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ jobs:
8181
- name: Fix git dir
8282
run: git config --global --add safe.directory $(pwd)
8383

84-
# Needed until we improve the build system.
85-
- name: Create dummy jni dir
86-
run: mkdir -p android/app/build/extraJni
87-
8884
- name: Re-generate lockfile
8985
run: android/scripts/update-lockfile.sh
9086

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 {

android/scripts/update-lockfile.sh

+19-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ GRADLE_OPTS="-Dorg.gradle.daemon=false"
1111
# We must provide a template for mktemp to work properly on macOS.
1212
GRADLE_USER_HOME=$(mktemp -d -t gradle-home-XXX)
1313
TEMP_GRADLE_PROJECT_CACHE_DIR=$(mktemp -d -t gradle-cache-XXX)
14-
GRADLE_TASKS=("assemble" "compileDebugUnitTestKotlin" "assembleAndroidTest" "lint")
14+
# Task list to discover all tasks and their dependencies since
15+
# just running the suggested 'help' task isn't sufficient.
16+
GRADLE_TASKS=(
17+
"assemble"
18+
"compileDebugUnitTestKotlin"
19+
"assembleAndroidTest"
20+
"lint"
21+
)
22+
EXCLUDED_GRADLE_TASKS=(
23+
"-xensureRelayListExist"
24+
"-xensureJniDirectoryExist"
25+
)
1526

1627
export GRADLE_OPTS
1728
export GRADLE_USER_HOME
@@ -30,6 +41,12 @@ echo ""
3041

3142
echo "Removing old components..."
3243
sed -i '/<components>/,/<\/components>/d' ../gradle/verification-metadata.xml
44+
echo ""
3345

3446
echo "Generating new components..."
35-
../gradlew -q -p .. --project-cache-dir "$TEMP_GRADLE_PROJECT_CACHE_DIR" -M sha256 "${GRADLE_TASKS[@]}"
47+
# Using a loop here since providing all tasks at once result in gradle task dependency issues.
48+
for GRADLE_TASK in "${GRADLE_TASKS[@]}"; do
49+
echo "Gradle task: $GRADLE_TASK"
50+
../gradlew -q -p .. --project-cache-dir "$TEMP_GRADLE_PROJECT_CACHE_DIR" -M sha256 "$GRADLE_TASK" "${EXCLUDED_GRADLE_TASKS[@]}"
51+
echo ""
52+
done

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/app/build/extraAssets/relays.json
115116

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

0 commit comments

Comments
 (0)