Search code examples
androidgradlekotlincordova-android

Gradle failure - null VariantManager


My project is no longer building - here's the error I get when trying to build in Android Studio:

null cannot be cast to non-null type com.android.build.gradle.internal.VariantManager Possible causes for this unexpected error include:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

I cleared Gradle's dependency cache, and I've restarted multiple times, so I believe I've ruled out the first 2 possible causes above. My project has also stopped building for others on my team, so it's not likely a local cache issue.

The third possible cause is interesting. This stopped working without any changes to my code/configuration (and it now fails with previous versions of our code which have built successfully), but we do have 3rd party cordova plugins which could get updated, and those can use gradle plugins.

What could be causing this build failure, or how can I debug it?


Solution

  • Found the problem - the kotlin-android plugin had a patch version update which broke my build. To find it, I removed the gradle plugins in my project one at a time until it started building again; I hope this helps someone else!