Skip to content

Commit

Permalink
gradle: Fix merge*JniLibFolders dependency on cargoBuild* task
Browse files Browse the repository at this point in the history
mozilla/rust-android-gradle#118 (comment)

Observations:
- The relevant task is called `cargoBuildArm64`, but it's ran as an
  intermediate dependency of `cargoBuild`;
- `buildDir.resolve()` doesn't exist (deprecated? It's not in the Java
  21 docs), but the sub-path `new File()` constructor does;
- `it.toolchain` on `com.nishtahir.CargoBuildTask` is `null` outside of
  `project.afterEvaluate`;
- Using purely typed `withType` queries allows one to write the
  expression without hardcoded task names, and automatically link
  all relevant tasks together.
  • Loading branch information
MarijnS95 committed Oct 24, 2023
1 parent f443b22 commit e52c9ec
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ cargo {
targets = ["arm64"]
}

tasks.configureEach { task ->
if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
task.dependsOn 'cargoBuild'
project.afterEvaluate {
tasks.withType(com.nishtahir.CargoBuildTask).forEach { buildTask ->
tasks.withType(com.android.build.gradle.tasks.MergeSourceSetFolders).configureEach {
it.inputs.dir(new File(new File(buildDir, "rustJniLibs"), buildTask.toolchain.folder))
it.dependsOn(buildTask)
}
}
}

0 comments on commit e52c9ec

Please sign in to comment.