flutter_libphonenumber icon indicating copy to clipboard operation
flutter_libphonenumber copied to clipboard

The Android module needs an upgrade

Open thuytrinh opened this issue 2 years ago • 11 comments

I have a Flutter project and its Android project is running with the following configuration:

  • Kotlin 1.8.20
  • Android Gradle Plugin 7.4.2
  • Gradle 8.1.1

After upgrading my Android Studio to Flamingo 2022.2.1 Patch 1, I had to point the Java home to the internal one inside Android Studio, which is jbr17. Then I had to upgrade the Android project to target Java 17 like below:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = '17'
    }
}

Afterwards I had a build error with the flutter_libphonenumber_android module:

Execution failed for task ':flutter_libphonenumber_android:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

* 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.

So I guess the flutter_libphonenumber_android module needs an upgrade to be able to run with the latest Android build tool. For now, to overcome the issue, I had to work around like below in the root build file of my Android module:

project(':flutter_libphonenumber_android').afterEvaluate {
    project(':flutter_libphonenumber_android').android {
        compileSdkVersion 30
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_17
            targetCompatibility JavaVersion.VERSION_17
        }

        kotlinOptions {
            jvmTarget = '17'
        }
    }
}

thuytrinh avatar May 06 '23 19:05 thuytrinh

That's odd - i'm not sure I understand. Are you saying you have to downgrade your app to use 1.7 not 1.8?

acoutts avatar Jun 08 '23 12:06 acoutts

Are you saying you have to downgrade your app to use 1.7 not 1.8?

No. It's Java 17 (seventeen) not 1.7. The flutter_libphonenumber_android project isn't compatible with the toolchain that I've mentioned earlier.

thuytrinh avatar Jun 08 '23 12:06 thuytrinh

Ah thanks. What's the output of flutter doctor -v for you?

acoutts avatar Jun 08 '23 12:06 acoutts

[✓] Flutter (Channel stable, 3.10.2, on macOS 13.4 22F66 darwin-arm64, locale en-DE)
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9cd3d0d9ff (2 weeks ago), 2023-05-23 20:57:28 -0700
    • Engine revision 90fa3ae28f
    • Dart version 3.0.2
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Platform android-33, build-tools 33.0.2
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] Android Studio (version 2022.2)
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Community Edition (version 2023.1.1)
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Community Edition (version 2023.1.2)
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.78.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.66.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 114.0.5735.106

[✓] Network resources
    • All expected network resources are available.

• No issues found!

thuytrinh avatar Jun 08 '23 13:06 thuytrinh

Thanks! Ok im testing some fixes now, going to push it to a branch and will ping you here to try it after that.

acoutts avatar Jun 08 '23 13:06 acoutts

Issue seems to be this: https://kotlinlang.org/docs/gradle-configure-project.html#check-for-jvm-target-compatibility-of-related-compile-tasks

I think i solved it by bumping everything to the latest and moving compileSdk to 33. But i'm not sure if this will break it for backwards compatibility. Try this:

dependency_overrides:
  flutter_libphonenumber_android:
    git:
      url: https://github.com/acoutts/flutter_libphonenumber.git
      ref: bump-android-sdk-33

Opened https://github.com/acoutts/flutter_libphonenumber/pull/50

acoutts avatar Jun 08 '23 13:06 acoutts

any update when a fix will land in the package? My project depends on the phone validation and is now stuck because it does not build the release version caused by this package.

The workaround is not working for me because it throws an error when building.

Execution failed for task :flutter_libphonenumber_android:compileReleaseJavaWithJavac.
error: invalid source release: 17

emmaxCreative avatar Nov 01 '23 16:11 emmaxCreative

Also running into this issue with kotlin version 1.9.20 and gradle distribution URL of 8.4. Above dependency override didn't work:

> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

masterwok avatar Dec 05 '23 14:12 masterwok

I'm needing this upgrade too.

For now, I will use this overrides to flutter_libphonenumber_android

dependency_overrides:
 flutter_libphonenumber_android:
   git:
     url: https://github.com/acoutts/flutter_libphonenumber.git
     path: packages/flutter_libphonenumer_android # You forgot this line
     ref: bump-android-sdk-33

Juniorlpes avatar Mar 25 '24 14:03 Juniorlpes

Face the same issue as well, the configuration is as below:

  • Kotlin 1.9.20
  • Android Gradle Plugin 8.1.2
  • Gradle 8.0
  • Flutter SDK 3.16.5

lybur avatar Jun 11 '24 05:06 lybur

Same error here, I believe this error should be a priority

alexsandersarmento avatar Aug 09 '24 04:08 alexsandersarmento

Fixed in v2.3.1

acoutts avatar Aug 19 '24 15:08 acoutts