mozilla / rust-android-gradle

Apache License 2.0
1.03k stars 67 forks source link

Android Studio Build Analyzer warns about "Always-Run Tasks" #41

Open tmcguire opened 3 years ago

tmcguire commented 3 years ago

It looks like the cargoBuild<Target> tasks are always run when running gradle, because they don't specify an output. See this screenshot from Android Studio: BuildAnalyzerWarning

ncalexan commented 3 years ago

I think this could be improved, but I don't quite know how to do it myself. What we need is to add some annotated fields to the CargoBuildTask instances and set them with the information from https://github.com/mozilla/rust-android-gradle/blob/6e553c13ef2d9bb40b58a7675b96e0757d1b0443/plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt#L52-L67.

The hard thing here is having the dynamic values of the various configuration options set at the right times so that the annotated fields have the correct values when inspected.

ncalexan commented 3 years ago

I'll add that these tasks are expected to always run but to be very fast, because cargo build --target ... itself does input/output tracking.

tmcguire commented 3 years ago

Also the following warning is printed when running ./gradlew assembleDebug from command-line, I guess it's related:

> Task :<redacted>:cargoBuildArm
Property 'toolchain' is not annotated with an input or output annotation. This behaviour has been deprecated and is scheduled to be removed in Gradle 7.0. See https://docs.gradle.org/6.5/userguide/more_about_tasks.html#sec:up_to_date_checks for more details.```

I'll add that these tasks are expected to always run but to be very fast, because cargo build --target ... itself does input/output tracking.

Right, it is quite fast. I guess the issues for me are:

SupernaviX commented 2 years ago

When I upgraded to Gradle 7, I wasn't able to build my project anymore because of this. It looks like input/output annotations are required by gradle now, not just recommended.

Edit: never mind! the new plugin version (0.9.0) somehow builds successfully.

ncalexan commented 2 years ago

~When I upgraded to Gradle 7, I wasn't able to build my project anymore because of this. It looks like input/output annotations are required by gradle now, not just recommended.~

Edit: never mind! the new plugin version (0.9.0) somehow builds successfully.

Woot woot! The new plugin version specifically added support for newer Gradle and Android-Gradle Plugin versions, so I'm thrilled that it's working as expected.

As to the actual content of this ticket, these always-run tasks are by design: only Cargo itself can determine if the task needs to run :(