I’ve had a flutter project I’ve run on iOS and Android with no issues for the past month. Recently I finished development and build a release version that I had to upgrade kotlin for, all good. However I tried to make some final changes and run on debug again to check compatibility and the app closes as soon as it launches.
I have experience with iOS but I’m absolutely lost on what to do with Android Studio.
- Downgrade java to 17?
- Upgrade Gradle to 8.5? (which supports java 21?)
- Some configuration error in my project?
There have been other questions very similar to this about version 63 and 61 but I haven’t been able to resolve this with the advice from those questions.
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.4.1 23E224 darwin-arm64, locale en-AU)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.89.0)
[✓] Connected device (5 available)
[✓] Network resources
$ java --version
OpenJDK 64-Bit Server VM Homebrew (build 21.0.2, mixed mode, sharing)
$ ./gradlew clean -scan
Task :gradle:compileGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':gradle:compileGroovy'.
BUG! exception in phase 'semantic analysis' in source unit '/Users/myName/Applications/Flutter/flutter/packages/flutter_tools/gradle/src/main/groovy/app_plugin_loader.groovy'
Unsupported class file major version 65
So it looks like I’m using Java 21 which is not supported by my project build files?
The only changes I made to build the release version of my app was change the kotlin version from 1.7.10 >> 1.9.24.
Since then I’ve upgraded Gradle from 7.3 >> 7.6.1
Here’s my flutter android config files:
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-7.6.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
settings.gradle
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
}
settings.ext.flutterSdkPath = flutterSdkPath()
includeBuild("${settings.ext.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 '7.4.2' apply false
// START: FlutterFire Configuration
id "com.google.gms.google-services" version "4.3.15" apply false
id "com.google.firebase.crashlytics" version "2.8.1" apply false
// END: FlutterFire Configuration
id "org.jetbrains.kotlin.android" version "1.9.24" apply false // was 1.7.10
}
build.gradle (app-level)
...
android {
namespace "..."
compileSdk flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "..."
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
// Load signing information
signingConfigs {
release { ... }
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
}
}
}
flutter { ... }
dependencies { ... }
Any ideas? Thank you
I’ve tried
- flutter clean, flutter pub get, flutter run
- Deleted app from device
- Restarted emulator
- Upgrade Gradle to a later version 7.6
- Modified gradel-wrapper.properties to include new gradle version
- Downgraded kotlin (upgraded again as this doesn’t work)
2
Answers
Turns out the build issue was resolved when I upgraded gradle to 8.5 but another issue persisted. I had changed the bundle id / application id prior to building the release build and it wasn't changed in the MainActivity.kt file which lead to the app being closed as the main activity was not matching the app id. Didn't have to downgrade java in the end.
Answer that helped: https://stackoverflow.com/a/53760198/9770208
Gradle 7.6 is never going to work with Java 21 since, as you observed, Java 21 is not supported until Gradle 8.4.
You’re going to have to upgrade Gradle, or downgrade Java.
If your main priority is just getting it to work, downgrading Java is likely to be an easier approach since it’s possible some other tools won’t be fully compatible with Java 21 yet.