0

I get the same error for all my other projects

I'm working on Form Validation emails, password, name and the app was working find I didn't change anything in my code! Suddenly when I tried to run my app I got this error, I tired flutter clean, flutter upgrade...etc and still having the same problem

 FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\-\StudioProjects\-\android\app\build.gradle' line: 24

* What went wrong:
A problem occurred evaluating project ':app'.
> Unknown constant tag 41 in class file javax/management/MBeanServer

* 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 856ms
Exception: Gradle task assembleDebug failed with exit code 1 

The build.gradle' line: 24 is as the follow

 apply plugin: 'com.android.application'

I ran flutter doctor and there's no issues

 D:\src\flutter\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.22000.795], locale en-US)
    • Flutter version 3.0.5 at D:\src\flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (3 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
    • Android SDK at C:/Users/Sully/AppData/Local/Android/Sdk
    • Platform android-33, build-tools 32.0.0-rc1
    • ANDROID_HOME = C:/Users/Sully/AppData/Local/Android/Sdk
    • Java binary at: D:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

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

[√] Android Studio (version 2021.1)
    • Android Studio at D:\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 11.0.11+9-b60-7590822)

[√] VS Code (version 1.66.2)
    • VS Code at C:\Users\Sully\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.38.1

[√] Connected device (3 available)
    • SM N986B (mobile) • R5CT11TPK3M • android-arm64  • Android 12 (API 31)
    • Windows (desktop) • windows     • windows-x64    • Microsoft Windows [Version 10.0.22000.795]
    • Edge (web)        • edge        • web-javascript • Microsoft Edge 103.0.1264.77

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
Process finished with exit code 0

android\app\build.gradle

 def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    ndkVersion flutter.ndkVersion
    compileSdkVersion 32
    compileSdkVersion 31

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.emart"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion flutter.minSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        minSdkVersion 31
        targetSdkVersion flutter.targetSdkVersion
        multiDexEnabled true
    }

    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 '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'

}

configurations.all {
    resolutionStrategy.force 'com.android.support:support-v4:24.0.0'
}
Sally
  • 11
  • 2

1 Answers1

0

Maybe you are a having problem with your gradle version checkout the answer of this question this might help you Flutter build.gradle Error " Build failed with an exception." and also the comments.

Ninad7N
  • 544
  • 4
  • 13
  • Thanks for the answer but they are already at `android/build.gradle` not in `android/app/build.gradle` – Sally Jul 31 '22 at 07:36
  • Just try the solution...if its did not work then you can always undo the changes. – Ninad7N Jul 31 '22 at 07:39
  • sorry it was my mistake I post it the 24th line in the **android/build.gradle**, I edited it the correct line 24th mentioned error is `apply plugin: 'com.android.application'` – Sally Jul 31 '22 at 07:47
  • will you edit your question with build.gradle file and also with your gradle version? – Ninad7N Jul 31 '22 at 08:02
  • I only edited the question, the correct 24 line for the problem is **apply plugin: 'com.android.application'** – Sally Jul 31 '22 at 08:07
  • I just found out that **I get the same error for all my other projects when I try to run them** – Sally Jul 31 '22 at 08:12
  • **apply plugin: 'com.android.application'** does not have any problem in app\build.gradle , the error might be something else in that file. just put your gradle file in the question – Ninad7N Jul 31 '22 at 08:12
  • Upgrade your gradle version also,... – Ninad7N Jul 31 '22 at 08:14
  • Thanks i did, but got this error `A problem occurred configuring root project 'android'. > Could not resolve all files for configuration ':classpath'. > Could not find com.android.tools.build:gradle:7.4.2.` – Sally Jul 31 '22 at 08:50
  • check the edited code's syntax – Ninad7N Jul 31 '22 at 09:07