acoutts / flutter_libphonenumber

Leverages libphonenumber to allow for asynchronous and synchronous formatting of phone numbers in Flutter apps. Includes a TextInputFormatter to allow real-time AsYouType formatting.
MIT License
60 stars 73 forks source link

The Android module needs an upgrade #45

Closed thuytrinh closed 2 months ago

thuytrinh commented 1 year ago

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

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'
        }
    }
}
acoutts commented 1 year ago

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?

thuytrinh commented 1 year ago

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.

acoutts commented 1 year ago

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

thuytrinh commented 1 year ago
[✓] 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!
acoutts commented 1 year ago

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 commented 1 year ago

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

emmaxCreative commented 12 months ago

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
masterwok commented 10 months ago

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).
Juniorlpes commented 7 months ago

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
lybur commented 4 months ago

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

alexsandersarmento commented 2 months ago

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

acoutts commented 2 months ago

Fixed in v2.3.1