After installing firebase_core
and firebase_auth
,
I didn't reproduce the exception like yours. This means that it works fine with my setup.
Before anything else, these are some prerequisites and build setups to consider:
flutter doctor -v
output:
[√] Flutter (Channel stable, 3.24.5, on Microsoft Windows [Version 10.0.26100.2454], locale en-US)
• Flutter version 3.24.5 on channel stable at C:\Users\alagu\FlutterSDK\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision dec2ee5c1f (10 days ago), 2024-11-13 11:13:06 -0800
• Engine revision a18df97ca5
• Dart version 3.5.4
• DevTools version 2.37.3
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
• Android SDK at C:\Users\alagu\AppData\Local\Android\Sdk
• Platform android-35, build-tools 35.0.0
• ANDROID_SDK_ROOT = C:\Users\alagu\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Java\jdk-17\bin\java
• Java version Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
• 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 Enterprise 2022 17.10.2)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Enterprise
• Visual Studio Enterprise 2022 version 17.10.35004.147
• Windows 10 SDK version 10.0.22621.0
[√] Android Studio (version 2022.3)
• Android Studio at C:\Program Files\Android\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.11+0--11852314)
[√] Android Studio (version 2024.1)
• Android Studio at C:\Program Files\Android\Android Studio1
• 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.10+0--11609105)
[√] VS Code (version 1.95.3)
• VS Code at C:\Users\alagu\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.100.0
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26100.2454]
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.86
• Edge (web) • edge • web-javascript • Microsoft Edge 131.0.2903.63
[√] Network resources
• All expected network resources are available.
• No issues found!
Please notice that I'm using Java 17, and I am using Android Studio for some Flutter development setup purposes.
So make sure that you are utilizing Java 17 and have it verified with proper configuration in the system variables.
settings.gradle file:
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.1.4" apply false
id "org.jetbrains.kotlin.android" version "2.0.21" apply false
}
include ":app"
gradle-wrapper.properties file:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
app\build.gradle file:
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.example.flutter_build_ref3"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.flutter_build_ref3"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = 23 //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 = "../.."
}
The provided configuration setup is only applicable to my environment setup, so you don't have to copy it unless we have the same environment setup (i.e., based on the generated information from flutter doctor -v
)
Since you have an exception,
Error: Could not find or load main class worker.org.gradle.process.internal.worker.GradleWorkerMain Caused by: java.lang.ClassNotFoundException: worker.org.gradle.process.internal.worker.GradleWorkerMain
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':gradle:compileGroovy'.
> Failed to run Gradle Worker Daemon
> Process 'Gradle Worker Daemon 4' finished with non-zero exit value 1
So, there's a conflict in compiling the core components of your build.
Again, be sure that you properly add the Java 17 SDK
or Java 11 SDK
path installation in the JAVA_HOME
and PATH
under the system variables
.
After you configure your Environment Variables > system variables. A Windows restart is a best practice to make sure that the JDK is integrated properly within your machine (just to make sure XD).
Then repeat the usual steps, perform flutter clean
, then flutter pub get
.
Then, build your app again.
Update:
Don't be confused about wondering why your Flutter app
worked well before but suddenly introduced a build exception
after installing a certain plugin
. You have to take note that other versions of Java JDK
might maintain compatibility with your previous build. But, unfortunately, some particular plugins or dependencies triggered the compatibility issues, so the conciseness of the Java JDK should be provided, or else your build won't be executed properly.
Clarifications:
Please make sure that you didn't manually add the firebase_core
and firebase_auth
plugins directly to the pubspec.yaml,
unless you know what you're doing. I suggest adding it by flutter pub add firebase_core
and flutter pub add firebase_auth
because your IDE will determine which version is compatible with your environment and development setup.
If there's some other newly introduced exception, and you are continually configuring your development setup.
Please consider the following debugging approaches:
PS C:\PATH_TO_YOUR_PROJECT\android> ./gradlew build --stacktrace --info
For logging optimizations where you only get what you need, please read Logging
To get the complete information about your building process.
UPDATE 2.0:
I just want to make things clear; you need to do this if you suspect that your Flutter project config messed up UNINTENTIONALLY
Here's what I performed:
Since the conflict you encountered is related to the java.lang.ClassNotFoundException
and Gradle. But to mention my previous case, I verified the root cause by myself by initially setting up a certain environment setup (e.g., Java 17 [since it works for me]) and then I created a new Flutter application.
I reviewed the configuration files and compared them to my actual Flutter project, so I was able to cross-check where the improper configurations were.
(in my newly created Flutter application) Then I add the plugin through these commands in the terminal:
flutter clean
NOTE: This is optional, sometimes I do this when I feel it's necessary, but since the issue is related to the Gradle build, it is better to clear up its caches to prevent further conflicts.
flutter pub get
flutter pub add <plugin_name>
NOTE: A certain plugin that I am using which also introduced an exception with my actual project.
flutter pub get
Then, I will build the app based on requirements (i.e., whether I need to build for Android or web).
or sometimes, I go to the Android directory within my project just to run a platform-specific command for Android:
PS C:\path_to_your_project\android> ./gradlew build --stacktrace --info
To relate to your case, you need to adjust your side for the plugin you used to become compatible, of course, based on the suggestions of the exception of the log if there's one.
If it is about java.lang.ClassNotFoundException
, migrate to Java 17 and perform gradle-specific and platform-specific (i.e., Android) clear caching, but sometimes flutter clean
will do. Since you already know what are the proper configurations based on your environment setup, repeating the UPDATE 2.0 will become optional.
Also, note that this is considered as one of the last resorts if you get confused with your project setup. Please don't get me wrong, I didn't mean to say that you're confused, but instead to give you an insight in order to overcome your case issue.
Reading the plugin's changelog is a good practice as well, btw.
PS: Sorry for being too verbose here, I need to do this to express my knowledge and understanding about the troubleshooting of your case.
I hope it helps! ❤️
cd android
and then./gradlew build --stacktrace --info