fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.62k stars 979 forks source link

[Bug]: Cannot build connectivity_plus due to error: lambda expressions are not supported in -source 7 despite the app configuration specifying java 1.8 for compilation #1791

Closed insidewhy closed 1 year ago

insidewhy commented 1 year ago

We saw in the Changelog.md for release 2.0.2 the following log:

Fix for error: lambda expressions are not supported in -source 7

But we seem to still be getting the error shown in the github issue title. I was able to hack around it by editing ~/.pub-cache/hosted/pub.dev/connectivity_plus-3.0.6/android/build.gradle and adding the following to the android section:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

We were eventually able to work around this properly by upgrading to gradle 7.3, for info on how we did this please see the end of this report.

This could be fixed for older versions of gradle by adding the configuration above to your android/build.gradle, otherwise I think the documentation should be updated to specify what the minimum gradle requirements are so others don't lose as much time diagnosing this as I have.

Platform

Android 12

Plugin

connectivity_plus

Version

3.0.6

Flutter SDK

3.7.12

Steps to reproduce

In our case connectivity_plus 3.0.6 is a transitive dependency of graphl_flutter 5.1.2

When we try to build (via flutter build apk) we get this error:

/root/.pub-cache/hosted/pub.dev/connectivity_plus-3.0.6/android/src/main/java/dev/fluttercommunity/plus/connectivity/ConnectivityBroadcastReceiver.java:86: error: lambda expressions are not supported in -source 7
    Runnable runnable = () -> events.success(connectivity.getNetworkType());
                           ^
  (use -source 8 or higher to enable lambda expressions)
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':connectivity_plus:compileReleaseJavaWithJavac'.

Yet we have the following in android/app/build.gradle:

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

Other relevant config seems to be:

kotlinOptions {
    jvmTarget = '1.8'
}

javac is version 11:

% javac --version
javac 11.0.17

Code Sample

No response

Logs

N/A

Flutter Doctor

[!] Flutter (Channel unknown, 3.7.12, on Ubuntu 22.04.1 LTS 5.15.0-1030-aws, locale en_US.UTF-8)
    ! Flutter version 3.7.12 on channel unknown at /sdks/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at
      https://flutter.dev/docs/get-started/install.
    ! Unknown upstream repository.
      Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    • Framework revision 4d9e56e694 (3 weeks ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git"
      directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /opt/android-sdk-linux
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /opt/android-sdk-linux
    • ANDROID_SDK_ROOT = /opt/android-sdk-linux
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang), or can be downloaded from
      https://releases.llvm.org/
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake), or can be downloaded from
      https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from
      https://github.com/ninja-build/ninja/releases
    ✗ pkg-config is required for Linux development.
      It is likely available from your distribution (e.g.: apt install pkg-config), or can be downloaded from
      https://www.freedesktop.org/wiki/Software/pkg-config/

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.1 LTS 5.15.0-1030-aws

Checklist before submitting a bug

Our eventual solution

We had to edit android/build.gradle and change classpath 'com.android.tools.build:gradle:4.1.0' to classpath 'com.android.tools.build:gradle:7.0.0'.

Then we edited android/gradle/wrapper/gradle-wrapper.properties and changed distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip to distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip.

Then we edited gradle/wrapper/gradle-wrapper.properties and changed distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip to distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip.

vbuberen commented 1 year ago

Thanks for reporting. There will be a new release later today where compileOptions are specified already for all plugins as it was done last week. Also there will be a requirement to use at least 4.2 Android Gradle plugin. It is great that you have updated your project to 7.0 already as 4.1.0 is really old one and shouldn't be used as of today.

vbuberen commented 1 year ago

Closing as new version is released