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

flutter app not building to some kotlin kotlinOptions not being specified #147185

Closed
AbdeMohlbi opened this issue Apr 22, 2024 · 7 comments · Fixed by #147326
Closed

flutter app not building to some kotlin kotlinOptions not being specified #147185

AbdeMohlbi opened this issue Apr 22, 2024 · 7 comments · Fixed by #147326
Assignees
Labels
c: regression It was better in the past than it is now found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on P1 High-priority issues at the top of the work list platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version t: gradle "flutter build" and "flutter run" on Android team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@AbdeMohlbi
Copy link

Steps to reproduce

when creating a new flutter project using the flutter create project then updating the settings.gradle as follows(i'm using gradle 8.6 ) :

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.3.2" apply false
    id "org.jetbrains.kotlin.android" version "1.9.23" apply false
}

include ":app"

i'm getting this error :

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

  Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
  Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation 

* 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 3m 8s
Error: Gradle task assembleDebug failed with exit code 1

Expected results

well it supposed to work without any issues (this was my config always for flutter 3.19.6 and it always worked even with 3.19.5)
i've seen : stackoverflow,and this video
so after doing that i could run the app normally by updating the app/build.gradle like that :

plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace = "com.AbdeMohlbi.todo_app"
    compileSdk = flutter.compileSdkVersion
    ndkVersion "25.1.8937393"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
// here
    kotlinOptions{
        jvmTarget=JavaVersion.VERSION_1_8
    }
// here
    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.AbdeMohlbi.todo_app"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.debug
        }
    }
}

flutter {
    source = "../.."
}

my question is should the minimal tempalte app trigger this kind of error ? if this is the case i guess this block need to be added to the app/build.gradle file

Actual results

this error apears :

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17).

  Consider using JVM Toolchain: https://kotl.in/gradle/jvm/toolchain
  Learn more about JVM-target validation: https://kotl.in/gradle/jvm/target-validation 

* 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 3m 8s
Error: Gradle task assembleDebug failed with exit code 1

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text("a"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),

          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: ()=>print("wtf"),
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[√] Flutter (Channel master, 3.22.0-15.0.pre.1, on Microsoft Windows [version 10.0.19045.4239], locale en-US)
    • Flutter version 3.22.0-15.0.pre.1 on channel master at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 1a905d508d (33 hours ago), 2024-04-21 06:44:23 -0400
    • Engine revision 75ca2195c9
    • Dart version 3.5.0 (build 3.5.0-83.0.dev)
    • DevTools version 2.35.0-dev.8

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\bougara computer\AppData\Local\Android\Sdk
    • Platform android-UpsideDownCakePrivacySandbox, build-tools 34.0.0
    • Java binary at: C:\Users\bougara computer\Desktop\android-studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.3.2)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.3.32819.101
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2023.3)
    • Android Studio at C:\Users\bougara computer\Desktop\android-studio
    • 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.9+0--11185874)

[√] VS Code, 64-bit edition (version 1.88.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.72.0

[√] Connected device (4 available)
    • M2003J15SC (mobile) • 05d3e1490405 • android-arm64  • Android 11 (API 30)
    • Windows (desktop)   • windows      • windows-x64    • Microsoft Windows [version 10.0.19045.4239]
    • Chrome (web)        • chrome       • web-javascript • Google Chrome 123.0.6312.124
    • Edge (web)          • edge         • web-javascript • Microsoft Edge 124.0.2478.51
@huycozy huycozy added the in triage Presently being triaged by the triage team label Apr 23, 2024
@huycozy
Copy link
Member

huycozy commented Apr 23, 2024

Thanks for filing the issue. I also can reproduce this on a new project created with Flutter master channel, it doesn't occur with Flutter stable 3.19.6.

flutter doctor -v (stable and master)
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.19.6 on channel stable at /Users/huynq/Documents/GitHub/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (31 hours ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode15.3.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2023.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
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

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

[✓] Connected device (3 available)
    • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
    • macOS (desktop)  • macos            • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 123.0.6312.124

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

• No issues found!
[!] Flutter (Channel master, 3.22.0-15.0.pre.15, on macOS 14.1 23B74 darwin-x64, locale en-VN)
    • Flutter version 3.22.0-15.0.pre.15 on channel master at /Users/huynq/Documents/GitHub/flutter_master
    ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 89a4ffaad5 (56 minutes ago), 2024-04-22 22:16:42 -0400
    • Engine revision f8e373da52
    • Dart version 3.5.0 (build 3.5.0-86.0.dev)
    • DevTools version 2.35.0-dev.8
    • 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 34.0.0)
    • Android SDK at /Users/huynq/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/huynq/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode15.3.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2023.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
    • android-studio-dir = /Applications/Android Studio.app/
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 14.1 23B74 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 124.0.6367.62

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

! Doctor found issues in 1 category.

@huycozy huycozy added c: regression It was better in the past than it is now platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. t: gradle "flutter build" and "flutter run" on Android has reproducible steps The issue has been confirmed reproducible and is ready to work on team-android Owned by Android platform team found in release: 3.22 Found to occur in 3.22 and removed in triage Presently being triaged by the triage team labels Apr 23, 2024
@AbdeMohlbi
Copy link
Author

@huycozy
Have u tried my fix has it work ?

@huycozy
Copy link
Member

huycozy commented Apr 23, 2024

Yes, adding kotlinOptions back can make it works

@reidbaker
Copy link
Contributor

@flutter/android-reviewers FYI
@bartekpacia fyi.

I think in general we will probably either remove or bump the java source compatibility from 1.8 to 11 or 17.

@reidbaker reidbaker added the P1 High-priority issues at the top of the work list label Apr 23, 2024
@AbdeMohlbi
Copy link
Author

@flutter/android-reviewers FYI
@bartekpacia fyi.

I think in general we will probably either remove or bump the java source compatibility from 1.8 to 11 or 17.

I don't know if this is related but i'm using jdk 21

@AbdeMohlbi
Copy link
Author

AbdeMohlbi commented Apr 27, 2024

@gmackall
i suggest this

kotlinOptions {
        jvmTarget = '1.8'
    }

also something weird but works(performs faster and i don't know why):

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile.class){
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }

@huycozy
Copy link
Member

huycozy commented May 7, 2024

@AbdeMohlbi I think we should keep this issue open until the linked PR got merged

@AbdeMohlbi AbdeMohlbi reopened this May 7, 2024
auto-submit bot pushed a commit that referenced this issue May 7, 2024
Adds jvmTarget to gradle templates. 

Fixes #147185.

Interestingly, we already had this in many of our examples/tests, see search results here https://github.com/search?q=repo%3Aflutter%2Fflutter%20jvmTarget&type=code.
@huycozy huycozy added the r: fixed Issue is closed as already fixed in a newer version label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: regression It was better in the past than it is now found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on P1 High-priority issues at the top of the work list platform-android Android applications specifically r: fixed Issue is closed as already fixed in a newer version t: gradle "flutter build" and "flutter run" on Android team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants