flutterkotlindartgradle

android_intent_plus fails Gradle build due to internal error in android_intent_plus?


I have upgraded just about everything in my Flutter project, and now I am getting a compile error when running ./gradlew build

It seems to me that the 3rd party dependency "android_intent_plus" is not using Mockito correctly, but I can't find anything about this online, so it must be working for other people.

What is going on, and how can I fix this? Is it a problem with android_intent_plus or with my project?

I have tried skipping tests for android_intent_plus, but this did not make any difference at all (build.gradle):

    project.tasks.withType(Test) {
        if (project.name == "android_intent_plus") {
            exclude '**/MethodCallHandlerImplTest.class'
        }
    }

I also tried this (build.gradle):

        if (project.name == 'android_intent_plus') {
            project.tasks.withType(Test) {
                enabled = false
            }
        }

I thought maybe it was because of a mismatch in the jvmTarget, but I have specifically set it to both version 1.8 and 17. Both produce the same result.

android {
    compileSdkVersion 34
    ndkVersion  "27.0.12077973"

    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    } 

The error I'm getting is this:

> Task :android_intent_plus:compileDebugUnitTestJavaWithJavac FAILED
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:7: error: cannot find symbol
import static org.mockito.Matchers.any;
                         ^
  symbol:   class Matchers
  location: package org.mockito
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:7: error: static import only from classes and interfaces
import static org.mockito.Matchers.any;
^
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:8: error: cannot find symbol
import static org.mockito.Matchers.eq;
                         ^
  symbol:   class Matchers
  location: package org.mockito
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:8: error: static import only from classes and interfaces
import static org.mockito.Matchers.eq;
^
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:37: error: cannot find symbol
  private IntentSender sender;
          ^
  symbol:   class IntentSender
  location: class MethodCallHandlerImplTest
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:38: error: cannot find symbol
  private MethodCallHandlerImpl methodCallHandler;
          ^
  symbol:   class MethodCallHandlerImpl
  location: class MethodCallHandlerImplTest
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:43: error: cannot find symbol
    sender = new IntentSender(null, null);
                 ^
  symbol:   class IntentSender
  location: class MethodCallHandlerImplTest
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:44: error: cannot find symbol
    methodCallHandler = new MethodCallHandlerImpl(sender);
                            ^
  symbol:   class MethodCallHandlerImpl
  location: class MethodCallHandlerImplTest
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:54: error: cannot find symbol
        .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
                           ^
  symbol:   method eq(String)
  location: class MethodCallHandlerImplTest
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:54: error: cannot find symbol
        .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
                                             ^
  symbol:   method any(Class<BinaryMessageHandler>)
  location: class MethodCallHandlerImplTest
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:68: error: cannot find symbol
        .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
                           ^
  symbol:   method eq(String)
  location: class MethodCallHandlerImplTest
/Users/anderspetteroe/.pub-cache/hosted/pub.dev/android_intent_plus-5.1.0/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java:68: error: cannot find symbol
        .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
                                             ^
  symbol:   method any(Class<BinaryMessageHandler>)
  location: class MethodCallHandlerImplTest
12 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':android_intent_plus:compileDebugUnitTestJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --info option to get more log output.
> Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.10/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 2s
198 actionable tasks: 3 executed, 195 up-to-date

Solution

  • I ended up upgrading a lot of the dependencies in my Flutter app, upgraded Flutter SDK and NDK to latest versions, upgraded Gradle to latest version, upgraded jvmTarget to 17 in stead of 1.8, and forced this onto all dependencies by adding this in gradle.build:

    def javaVersion = JavaVersion.VERSION_17
    project.android {
        def androidApiVersion = 34
        compileSdkVersion androidApiVersion
        defaultConfig {
            targetSdkVersion androidApiVersion
        }
        compileOptions {
            sourceCompatibility javaVersion
            targetCompatibility javaVersion
        }
    
      
      tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach 
        {
            kotlinOptions {
                jvmTarget = javaVersion.toString()
            }
        }
        lintOptions {
            disable 'SoonBlockedPrivateApi' // This should be removed as soon as image_picker has been updated.
        }
    }
    

    I also upgraded desugar_jdk_libs to 2.0.4.

    I still get errors in my 3rd party dependencies when I run ./gradlew build, but my app is now running and uploaded successfully to Google Play Store, so until the 3rd party plugins are updated, I think I've done all I can.