autonomousapps / dependency-analysis-gradle-plugin

Gradle plugin for JVM projects written in Java, Kotlin, Groovy, or Scala; and Android projects written in Java or Kotlin. Provides advice for managing dependencies and other applied plugins
Apache License 2.0
1.67k stars 115 forks source link

Could not determine the dependencies of task ':app:synthesizeProjectViewDebugTest'. #1111

Closed giovanischiar closed 4 months ago

giovanischiar commented 5 months ago

Build scan link https://scans.gradle.com/s/4qwwjyf5chvkk

Plugin version latest snapshot "+"

Gradle version 8.2

JDK version 17

(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version 1.9.21

(Optional) Android Gradle Plugin (AGP) version 8.2.1

Describe the bug When I add the id("com.autonomousapps.dependency-analysis") version "+" to root build.gradle and run ./gradlew projectHealth I got this error Could not determine the dependencies of task ':app:synthesizeProjectViewDebugTest'.

To Reproduce Steps to reproduce the behavior:

  1. Add id("com.autonomousapps.dependency-analysis") version "+" to root build.gradle
  2. Go to terminal and run ./gradlew projectHealth

Expected behavior The default output for projectHealth

autonomousapps commented 5 months ago

Thanks for the issue!

Hopefully the build scan will be enough, but do you have a minimal reproducer? Those repro steps don't look sufficient to me.

gabrielittner commented 5 months ago

I've got a reproducer, this is a new project created with Android Studio Hedgehog with the only change being that I added this plugin MyApplication.zip

ZacSweers commented 5 months ago

Here's another repro, just uncomment the commented out enabling of DAGP in the root build.gradle.kts: https://github.com/ZacSweers/CatchUp

autonomousapps commented 4 months ago

Duplicates https://github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/1112.

autonomousapps commented 4 months ago

I've got a reproducer, this is a new project created with Android Studio Hedgehog with the only change being that I added this plugin MyApplication.zip

@gabrielittner I downloaded this zip and ran buildHealth on it and there were no errors. Is there something I'm missing?

gabrielittner commented 4 months ago

I can still reproduce it when I download the zip and run buildHealth. However after deleting ~/.android/analytics.settings it doesn't reproduce anymore and as soon as the file is recreated it's happening again. Just the existence of the file seems to be enough, so you should be able to reproduce it by just creating it without content.

autonomousapps commented 4 months ago

how is that file used? I'm not familiar with it. do you have an example with actual content? links to documentation?

autonomousapps commented 4 months ago

I just checked and I already have such a file in my environment. The contents of it are

{"userId":"73484633-8bc3-4f83-9fcb-edcf4ec64b4e","hasOptedIn":false,"debugDisablePublishing":false,"saltValue":0,"saltSkew":-1}
gabrielittner commented 4 months ago

Mine looks the same and it's created/updated when you toggle "send usage statistics to Google" in Android Studio, other than that I don't know more about it. I was just thinking about it since the issue is analytics related. For me it happens regadless of whether "hasOptedIn" is true or false but maybe changing it true will help reproducing it?

autonomousapps commented 4 months ago

I changed the value to true and reran buildHealth (with --rerun-tasks) and it worked fine :shrug:

Have you tried with rerun-tasks?

gabrielittner commented 4 months ago

--rerun-tasks didn't help. I tried aroudn a bit more and it looks like you need to kill the daemon after changing hasOptedIn or generally use --no-daemon for the change to take effect.

autonomousapps commented 4 months ago

--no-daemon did it 🤔

Ok, so, to reproduce this error, it looks like at least two things need to be true:

  1. set hasOptedIn to true
  2. Run with --no-daemon ==> ./gradlew :app:explodeXmlSourceDebugTest --no-daemon
  3. ???

I note that this doesn't fail with the :app:explodeXmlSourceDebug task (for the main source set), nor does it fail for the :app:explodeXmlSourceDebugAndroidTest task (the androidTest source set). It's only failing for the test source set. I think this might relate to the Android unit tests not having resources enabled, and DAGP not handling that properly.

Further confirmation, the success cases all have tasks like :app:generateDebugAndroidTestResValues and :app:generateDebugResValues. There however is no task named :app:generateDebugTestResValues. (type: com.android.build.gradle.tasks.GenerateResValues.)

autonomousapps commented 4 months ago

I can eliminate the error by basically commenting out this method body for android unit tests. Given the whole chain is nullable, it is bizarre to me that this happens. It looks like an AGP bug.

  override fun getAndroidRes(): Provider<Iterable<File>> {
    // return project.provider { emptyList() }
    return sources.res?.all
      ?.map { layers -> layers.flatten() }
      ?.map { directories ->
        directories.map { directory -> directory.asFileTree.matching(Language.filterOf(Language.XML)) }
      }
      ?.map { trees -> trees.flatten() }
      ?: project.provider { emptyList() }
  }
autonomousapps commented 4 months ago

https://issuetracker.google.com/issues/325307775