Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown Kotlin JVM target: 21 #992

Open
TergelEnkhtur opened this issue Nov 22, 2024 · 0 comments
Open

Unknown Kotlin JVM target: 21 #992

TergelEnkhtur opened this issue Nov 22, 2024 · 0 comments

Comments

@TergelEnkhtur
Copy link

TergelEnkhtur commented Nov 22, 2024

Describe the bug
This error is bizarre as it runs fine when i run it in the android folder by clicking the run button in Android Studio, but does not run when I try to do the same in the root of the flutter project. The thing is, I am trying to publish this app to the Android and App stores and am worried that it will not pass the checks there or will fail to run in the users' phones if I ignore this error.

I followed this to have a working build for this plugin that uses Unity 6 as that is important for my project but sadly it did not work for me:
#967

Also this one:
https://stackoverflow.com/questions/79090643/android-studio-ladybug-unknown-kotlin-jvm-target-21

  • What went wrong:
    Could not determine the dependencies of task ':flutter_unity_widget:compileDebugKotlin'.

Unknown Kotlin JVM target: 21

This is the main error that pops up and I tried a lot of different things but could not fix it. Please help.

Steps I took

I got the build.cs file from the experimental/unity_6000 branch and replaced my own Assets/FlutterUnityIntegration/Editor/Build.cs file with it.

I made sure to bump the Kotlin version to Java 17 in app/build.gradle:

Details

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

   kotlin {
        jvmToolchain(17) // I also tried this, did not work
    }

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "mn.argun.arconte"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 23
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

I have also went to Android Studio -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle. Under Gradle Projects -> Gradle JDK. I changed it from GRADLE_LOCAL_JAVA_HOME: JetBrains Runtime 21.0.3 - aarch64 to homebrew-17: Homebrew OpenJDK 17.0.13.

This fixes the same Unknown Kotlin JVM target: 21 error when it first appears when I click the run button in the android folder, but does not it the root folder.

Also, File -> Project Structure looks like this in the root folder:
Screenshot 2024-11-22 at 14 31 40
The SDK used to be: No SDK, but I tried changing that to homebrew-17.

gradle-wrapper.properties:
distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip

I have also tried the recommended 8.9 version update, still the same.

android/settings.gradle:
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version '8.3.0' apply false
id "org.jetbrains.kotlin.android" version "1.9.10" apply false
}

To Reproduce
Steps to reproduce the behavior:
0. Use the example project or create new project

  1. Go to 'root of project folder'
  2. Click on 'run'
  3. See error

The 3 logs below seem to be the same error, but just in case they are different, I will list them.

This is the error log when I click the run button in the root of the project:

Details

Launching lib/main.dart on SM F936U in debug mode...
Running Gradle task 'assembleDebug'...
Variant 'debug', will keep symbols in binaries for:
  'libunity.so'
  'libil2cpp.so'
  'libmain.so'
Variant 'release', symbols will be stripped from binaries.
Your project is configured with Android NDK 23.1.7779620, but the following plugin(s) depend on a different Android NDK version:
- flutter_plugin_android_lifecycle requires Android NDK 25.1.8937393
- flutter_unity_widget requires Android NDK 25.1.8937393
- webview_flutter_android requires Android NDK 25.1.8937393
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to /Users/tergelenkhtur/Documents/Programming/Flutter_Projects/ARConte/android/app/build.gradle:

    android {
        ndkVersion = "25.1.8937393"
        ...
    }

Warning: SDK processing. This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':flutter_unity_widget:compileDebugKotlin'.
> Unknown Kotlin JVM target: 21

* 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.
> Get more help at https://help.gradle.org.

BUILD FAILED in 6s
Error: Gradle task assembleDebug failed with exit code 1

This is the log when i do 'flutter run' in the terminal in the root folder:

Details

tergelenkhtur@Tergels-MacBook-Pro ARConte % flutter run
Launching lib/main.dart on SM F936U in debug mode...
Variant 'debug', will keep symbols in binaries for:
  'libunity.so'
  'libil2cpp.so'
  'libmain.so'
Variant 'release', symbols will be stripped from binaries.
Your project is configured with Android NDK 23.1.7779620, but the following plugin(s) depend on a different Android NDK version:
- flutter_plugin_android_lifecycle requires Android NDK 25.1.8937393
- flutter_unity_widget requires Android NDK 25.1.8937393
- webview_flutter_android requires Android NDK 25.1.8937393
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to /Users/tergelenkhtur/Documents/Programming/Flutter_Projects/ARConte/android/app/build.gradle:

    android {
        ndkVersion = "25.1.8937393"
        ...
    }


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':flutter_unity_widget:compileDebugKotlin'.
> Unknown Kotlin JVM target: 21

* 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.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s
Running Gradle task 'assembleDebug'...                           1,185ms
Error: Gradle task assembleDebug failed with exit code 1

This is the log when i do 'flutter run' in the terminal by writing 'cd' to the android folder while still being in the root folder opened in Android Studio:

Details

tergelenkhtur@Tergels-MacBook-Pro ARConte % cd android
tergelenkhtur@Tergels-MacBook-Pro android % flutter run
Changing current working directory to: /Users/tergelenkhtur/Documents/Programming/Flutter_Projects/ARConte
Launching lib/main.dart on SM F936U in debug mode...
Variant 'debug', will keep symbols in binaries for:
  'libunity.so'
  'libil2cpp.so'
  'libmain.so'
Variant 'release', symbols will be stripped from binaries.
Your project is configured with Android NDK 23.1.7779620, but the following plugin(s) depend on a different Android NDK version:
- flutter_plugin_android_lifecycle requires Android NDK 25.1.8937393
- flutter_unity_widget requires Android NDK 25.1.8937393
- webview_flutter_android requires Android NDK 25.1.8937393
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to /Users/tergelenkhtur/Documents/Programming/Flutter_Projects/ARConte/android/app/build.gradle:

    android {
        ndkVersion = "25.1.8937393"
        ...
    }


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':flutter_unity_widget:compileDebugKotlin'.
> Unknown Kotlin JVM target: 21

* 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.
> Get more help at https://help.gradle.org.

BUILD FAILED in 924ms
Running Gradle task 'assembleDebug'...                           1,041ms
Error: Gradle task assembleDebug failed with exit code 1

This is when i do 'flutter run' with Android Studio open to the '/android' folder:

Details

tergelenkhtur@Tergels-MacBook-Pro android % flutter run
Changing current working directory to: /Users/tergelenkhtur/Documents/Programming/Flutter_Projects/ARConte
Launching lib/main.dart on SM F936U in debug mode...
Variant 'debug', will keep symbols in binaries for:
  'libunity.so'
  'libil2cpp.so'
  'libmain.so'
Variant 'release', symbols will be stripped from binaries.
Your project is configured with Android NDK 23.1.7779620, but the following plugin(s) depend on a different Android NDK version:
- flutter_plugin_android_lifecycle requires Android NDK 25.1.8937393
- flutter_unity_widget requires Android NDK 25.1.8937393
- webview_flutter_android requires Android NDK 25.1.8937393
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to /Users/tergelenkhtur/Documents/Programming/Flutter_Projects/ARConte/android/app/build.gradle:

    android {
        ndkVersion = "25.1.8937393"
        ...
    }


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':flutter_unity_widget:compileDebugKotlin'.
> Unknown Kotlin JVM target: 21

* 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.
> Get more help at https://help.gradle.org.

BUILD FAILED in 4s
Running Gradle task 'assembleDebug'...                              4.4s
Error: Gradle task assembleDebug failed with exit code 1

Expected behavior
I expect it to run without problems on my android phone.

Screenshots
I am sure you know this, but this is the run button in Android Studio I am talking about.
Screenshot 2024-11-22 at 11 53 11

This is the sync output in the android folder:
Screenshot 2024-11-22 at 14 24 44

This is the run/build output:
Screenshot 2024-11-22 at 14 25 42

This the Android Gradle Plugin version I am using and it is recommending me to update to 8.7.2 which I tried, does not make a difference:
Screenshot 2024-11-22 at 14 26 19

Unity (please complete the following information):

  • Version of Unity: 6000.0.16f1 and also tried with 6000.0.26f1
  • OS: Android
  • Version: Target API Level Android 6 (API Level 23)
  • Version: Minimum API Level Android 14 (API Level 34)
  • Graphics API: OpenGLES3
  • Scripting Backend: IL2CPP
  • Target Architectures: ARMv7, ARM64
  • Application Entry Point: Activity and not GameActivity
  • Active Input Handling: Both

Smartphone (please complete the following information):

  • Device: Samsung Galaxy Z Fold4
  • Model Name SM-F936U
  • OS: Android Version 14, One UI Version 6.1.1

Flutter doctor

Details

tergelenkhtur@Tergels-MacBook-Pro android % flutter doctor -v
[!] Flutter (Channel [user-branch], 3.24.1, on macOS 15.1.1 24B91 darwin-arm64, locale en-MN)
    ! Flutter version 3.24.1 on channel [user-branch] at /Users/tergelenkhtur/Documents/Programming/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/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    • Framework revision 5874a72aa4 (3 months ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2
    • 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 35.0.0)
    • Android SDK at /Users/tergelenkhtur/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.16.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 21.0.3+-79915917-b509.11)

[✓] Connected device (3 available)
    • Bachka’s iPhone (mobile)        • 00008110-000A1D5E217B801E • ios          • iOS 18.0.1 22A3370
    • macOS (desktop)                 • macos                     • darwin-arm64 • macOS 15.1.1 24B91 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin       • macOS 15.1.1 24B91 darwin-arm64
    ! Error: Browsing on the local area network for Ennkhee’s iPad. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for iphone 13 pro max. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

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

! Doctor found issues in 2 categories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant