Exception: Gradle task assembleDebug failed with exit code 1 (runs at web but doesn't at emulator) - flutter

I'm having this issue when I try to run the standard flutter new project app:
Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* Where:
Build file 'E:\AndroidStudioProjects\good_heart\android\app\build.gradle' line: 24
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.version-check']
> Minimum supported Gradle version is 6.5. Current version is 4.10.2. If using the gradle wrapper, try editing the distributionUrl in E:\AndroidStudioProjects\good_heart\android\gradle\wrapper\gradle-wrapper.properties to gradle-6.5-all.zip
* 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 16s
Exception: Gradle task assembleDebug failed with exit code 1
This happens when I try to run it in a android emulator (one provided by android studio), doesn't happen when I run it in Edge(web) though, it runs smoothly.
Any thoughts? Already tried installing older versions of JDK (such as 11 and 8). Reinstalling Android Studio and flutter... Running it from VScode outputs the same error.

If you Use Android Studio Emulator
Open AVD Manager then select your Emulator right click it and select or click on Wipe data or Cold Boot Now and then run or launch your app your project
hope its help to you

you need to update your Gradle wrapper
go to android/gradle/wrapper/gradle-wrapper.properties and change the last line to: distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip Android Studio will download the necessary library.

Related

Flutter app doesn't run FAILURE: Build failed with an exception

So I installed flutter and I initialized an app I run the app it
say's
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
Where: Build file 'C:\src\projects\myapp\android\app\build.gradle' line: 26
What went wrong: A problem occurred evaluating project ':app'.
Could not open dsl generic class cache for script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle'
(C:\Users\admin.gradle\caches\7.5\scripts\6retkvb9i1tmrre8676t631o1).
Unexpected lock protocol found in lock file. Expected 3, found 0.
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 5s Exception: Gradle task assembleDebug failed with
exit code 1
so I checked if I have problem with installation with flutter doctor and it
show's this
I already have system image and when I run the program it always shows the error
and the app doesn't run I already tried setting the JAVA_HOME and copying the jbr files to
jre but still get the error. Thank you for your response
you can visit these two post to solve your problem :
1- first error : Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. Flutter 2.0
2-for second error : Visual Studio not installed; this is necessary for Windows development

Gradle failed to build on a new hardware using the same installation method

After I copy my project to a new laptop, I tried to run a flutter project in vscode. however during debugging gradle failed to build and gave me this in the debug console
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
lib\main.dart:1
FAILURE: Build failed with an exception.
What went wrong:
Could not open settings generic class cache for settings file 'D:\PROJECT_NAME\android\settings.gradle' (C:\Users\Folder.gradle\caches\7.4\scripts\ea4ydi90mwjg9g63m7r6nimmx).
BUG! exception in phase 'semantic analysis' in source unit 'BuildScript' Unsupported class file major version 63
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 1s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
I have no idea what went wrong since the JDK is the same version (19) as my old laptop
edit: I tried to download a new gradle, and create a new empty project, and I still get the same error
Running a flutter project on the new laptop

Flutter project is not running on physical device

When I make a build of flutter project on windows(chrome) it run successfully but when i run on my phone it gives this error
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Failed to install the following SDK components:
tools Android SDK Tools
build-tools;29.0.2 Android SDK Build-Tools 29.0.2
The SDK directory is not writable (C:\Users\Cantt)
* 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 1m 44s
Exception: Gradle task assembleDebug failed with exit code 1
I installed the Andriod SDK platform 32 and 31. please help how to fix this issue.
Open android studio and go to SDK manager
Check SDK platforms API level 28, 29, 30
Then apply and ok
Then
flutter clean
flutter pub get
flutter run
Try the following on Android Studio.
Help>Find Action and then search for each and select:
clean project
rebuild project
Invalidate caches
Then restart Android Studio.
This should fix the issue.

There is a error in android studio but same code working on flutlab.io

i tried to run a basic code in android studio. but it showing error. but the same code successfully compiled on flutlab.io
here is the error message.
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* What went wrong:
Could not open settings generic class cache for settings file 'C:\Users\HP\AndroidStudioProjects\helloapp\android\settings.gradle' (C:\Users\HP\.gradle\caches\6.7\scripts\1fnwrr8g4rohfp291nvlxj5qe).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 60
* 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 2s
Exception: Gradle task assembleDebug failed with exit code 1
i'm new to android studio. so please tell what's the wrong here.
Try to use JAVA SDK 15.
First remove your old JDK, and download & install Java JDK 15 from here.
Then, in Android Studio, change the path to the Java JDK so that it matches the latest install. Finally, restart Android Studio to apply the changes.

Error "package_config.json does not exist" when running the project

I am currently learning flutter. Suddenly when i try to run my project i got the error that says "D:..\android.dart_tool\package_config.json does not exist.
Did you run this command from the same directory as your pubspec.yaml file?". I have checked the directory and it is correct. And there is no package_config.json when i go to the directory stated. Can someone tell me how to fix this? Or how to recreate the json file? Thank you in advance.
Microsoft Windows [Version 10.0.19042.906]
(c) Microsoft Corporation. All rights reserved.
D:\FlutterProject\wndr2u>flutter run
Using hardware rendering with device AOSP on IA Emulator. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
D:\FlutterProject\wndr2u\android\.dart_tool\package_config.json does not exist.
Did you run this command from the same directory as your pubspec.yaml file?
FAILURE: Build failed with an exception.
* Where:
Script 'D:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* 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 1s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 2,703ms
Exception: Gradle task assembleDebug failed with exit code 1
Flutter clean
Flutter pub get
Open the project in the android module
Generate APK or bundle
Run Tools > Flutter > Pub Get
It worked for me