flutterandroid-gradle-plugin

How to diagnose Gradle issues in Flutter


I have a strange error where one of the plugins I used for a long time suddenly started to give Unresolved reference errors (either if called directly, or not found at all when the toolchain tries to instantiate it from GeneratedPluginRegistrant.java). Import statements are present and correct. The really challenging part is that the same app compiles all right if initiated from the command line (flutter.bat build appbundle ...) and only shows the error when built from the IDE, which is Android Studio.

I get the usual error:

> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

But how can I get the log? I'm well aware of earlier similar questions but they don't work any more. Adding any of the options above to Settings > Build > Gradle-Android compiler > Command-line options has no influence. I do add -v to flutter run and the resulting output will be rather verbose, yes, but it shows everything before the error above in a verbose manner while it doesn't add any useful information to the actual error (apart from a stacktrace inside the compiler that is completely uninteresting here).

Using gradlew.bat --verbose, while working, doesn't interest me because, as I mentioned above, the error only appears when run from under the IDE, so a command line run will not help me.

I also tried GRADLE_OPTS or adding --debug directly into gradlew.bat in the line where it assembles the command but it doesn't change a thing in the output, or at least not anywhere that I can see it.

Versions for reference:

Caches were cleared many times, including File > Invalidate Caches in AS and also manually during testing. The problem can be reproduced with the relevant plugin stored both in the usual Pub package cache and as a local copy.


Solution

  • It works again now but I wouldn't say I fixed it, so I'm a bit afraid of when it will come back. At any rate, some items of interest for anybody stumbling across the same problem:

    In the end, there's a way to see the log. I said I had tried to modify gradlew.bat, among others. It finally worked but you have to add --debug, --verbose or --scan at the end, after %CMD_LINE_ARGS%. When I first tried, I put the extra switches after GRADLE_OPTS, as this was the place I found logical. It only works at the end. Also add the run argument -v in Edit Configurations and you'll get it. Actually, you get so much that it might overflow the Console's buffer.

    So, when I added --scan, I got the log entries. But more than that, the project returned to normal, it compiled. And it compiles since then. And while I'm glad it does, I don't have the feeling that I fixed it...