I've tried the solution in this stackoverflow QnA and also followed web links: this and this. Below is a summary of what I've tried:
Steps:
Checked my java version: My system had a java version 21.0.5, but this is not configured to be used as JAVA_HOME
environment variable is not set. So, the default java shipped with Android studio is used which is version 21.0.4 as stated in the output of flutter doctor --verbose
.
Checked the Compatibality Matrix and used both Gradle versions 8.4
and 8.5
shown parallel to Java version 21
in the configuration process that follows.
Opened a terminal, and went to <project_root>/android/
directory and executed the following commands:
./gradlew wrapper --gradle-version=8.4
This resulted in following error:
Welcome to Gradle 7.6.3!
Here are the highlights of this release:
- Added support for Java 19.
- Introduced `--rerun` flag for individual task rerun.
- Improved dependency block for test suites to be strongly typed.
- Added a pluggable system for Java toolchains provisioning.
For more details see https://docs.gradle.org/7.6.3/release-notes.html
Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details
> 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 '/home/ajthapa/dev/tooling/flutter/packages/flutter_tools/gradle/src/main/groovy/app_plugin_loader.groovy' Unsupported class file major version 65
* 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 14s
1 actionable task: 1 executed
The same thing happened with version 8.5
.
<project_root>/android/gradle/wrapper/gradle-wrapper.properties
in that directory, and changed the content of the original file from:distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
to:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
and then run the project which resulted in following error:
Launching lib/main.dart on sdk gphone64 x86 64 in debug mode...
Warning: 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.
Checking the license for package Android SDK Build-Tools 30.0.3 in /home/ajthapa/Android/Sdk/licenses
License for package Android SDK Build-Tools 30.0.3 accepted.
Preparing "Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)".
"Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" ready.
Installing Android SDK Build-Tools 30.0.3 in /home/ajthapa/Android/Sdk/build-tools/30.0.3
"Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" complete.
"Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" finished.
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
(Above warnings also arose with new projects, but the projects run. The following may be of our current concern:)
3 warnings
ERROR:/home/ajthapa/dev/projects/flutter/NepaliUnitConv/00__Play_Store_builds/00__Closed_Test_version/update__feature_tests/NepaliUnitConv_v1.0.29__without_Admob_Ads/nepali_unit_conv/build/path_provider_android/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Failed to transform classes.jar (project :path_provider_android) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, com.android.build.api.attributes.AgpVersionAttr=7.3.0, com.android.build.api.attributes.BuildTypeAttr=debug, com.android.build.gradle.internal.attributes.VariantAttr=debug, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingWithClasspathTransform: /home/ajthapa/dev/projects/flutter/NepaliUnitConv/00__Play_Store_builds/00__Closed_Test_version/update__feature_tests/NepaliUnitConv_v1.0.29__without_Admob_Ads/nepali_unit_conv/build/path_provider_android/intermediates/runtime_library_classes_jar/debug/classes.jar.
> Error while dexing.
* 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 4m 10s
Error: Gradle task assembleDebug failed with exit code 1
Exited (1).
My project ran perfectly when I had Android Studio Koala installed, and now these errors have risen when I removed Koala version and installed Ladybug.
How can I fix this?
Update 01: Output of flutter doctor --verbose
:
[✓] Flutter (Channel stable, 3.27.2, on Ubuntu 24.04.1 LTS 6.8.0-51-generic, locale en_GB.UTF-8)
• Flutter version 3.27.2 on channel stable at /home/ajthapa/dev/tooling/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 68415ad1d9 (4 days ago), 2025-01-13 10:22:03 -0800
• Engine revision e672b006cb
• Dart version 3.6.1
• DevTools version 2.40.2
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
• Android SDK at /home/ajthapa/Android/Sdk
• Platform android-35, build-tools 35.0.1
• Java binary at: /home/ajthapa/dev/tooling/android-studio/jbr/bin/java
• Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• Ubuntu clang version 18.1.3 (1ubuntu1)
• cmake version 3.28.3
• ninja version 1.11.1
• pkg-config version 1.8.1
[✓] Android Studio (version 2024.2)
• Android Studio at /home/ajthapa/dev/tooling/android-studio
• Flutter plugin version 83.0.3
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)
[✓] VS Code (version 1.96.4)
• VS Code at /usr/share/code
• Flutter extension version 3.102.0
[✓] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 15 (API 35) (emulator)
• Linux (desktop) • linux • linux-x64 • Ubuntu 24.04.1 LTS 6.8.0-51-generic
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.204
[✓] Network resources
• All expected network resources are available.
• No issues found!
you could try this settings. I've recently went through incompatibility issues like you :
I configured my Flutter JDK Directory on a Java 17 sdk and used these resources :
https://docs.gradle.org/current/userguide/compatibility.html
https://services.gradle.org/distributions/
Android getting error: Namespace not specified
android/app/build.gradle
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
android/settings.gradle
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.5.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.0" apply false
}
gradle-wrapper.properties
..
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
..
Also you may need this to fix the "Namespace Not Specified" error since Gradle 8 (Android getting error: Namespace not specified)
build.gradle
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
// this
subprojects {
afterEvaluate { project ->
if (project.hasProperty('android')) {
project.android {
if (namespace == null) {
namespace project.group
}
}
}
}
}
Hope it will help you