Flutter build issue: Dart snapshot generator failed with exit code -9 - android

I get following exception when building flutter apk or appbundle. It happens randomly. I don't know what triggers it. How can I debug this further?
Dart snapshot generator failed with exit code -9
FAILURE: Build failed with an exception.
* Where:
Script '/var/theproject/libs/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command '/var/theproject/libs/flutter/bin/flutter'' 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 6m 51s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 412.5s
Gradle task assembleRelease failed with exit code 1
Here is my flutter doctor -v result:
Flutter (Channel stable, 2.2.2, on Linux, locale en_US.UTF-8)
• Flutter version 2.2.2 at /var/theproject/libs/flutter
• Framework revision d79295af24 (6 days ago), 2021-06-11 08:56:01
-0700
• Engine revision 91c9fc8fe0
• Dart version 2.13.3
[✓] Android toolchain - develop for Android devices (Android SDK version
29.0.3)
• Android SDK at /var/theproject/libs/android-sdk-linux
• Platform android-30, build-tools 29.0.3
• Java binary at: /usr/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_282-b08)
• All Android licenses accepted.
[✗] Chrome - develop for the web (Cannot find Chrome executable at
google-chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome
executable.
[!] Android Studio (not installed)
• Android Studio not found; download from
https://developer.android.com/studio/index.html
(or visit
https://flutter.dev/docs/get-started/install/linux#android-setup for
detailed instructions).
[!] Connected device
! No devices available
! Doctor found issues in 3 categories.

I had the same problem, what it solved was to use variables from other class with static and not by creating a instance:
Works fine:
import file
ClassName.variable
Bug:
import file
var instance = ClassName()
instance.variable

Related

(Ubuntu) Flutter app (Android) error - Execution failed for task ':app:compileDebugJavaWithJavac'

I'm using Ubuntu 20.04. I've reinstalled flutter and android studio a few times but I can't make the below error go away. I've also tried the commands flutter clean and gradlew clean and tried to change compileSdkVersion, minSdkVersion and targetSdkVersion.
Launching lib/main.dart on sdk gphone x86 in debug mode...
lib/main.dart:1
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Could not create service of type UserHomeScopedCompileCaches using UserHomeScopeServices.createCompileCaches().
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 36s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
When I run flutter doctor:
$: flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on Ubuntu 20.04.4 LTS 5.13.0-44-generic,
locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version
32.1.0-rc1)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.2)
[✓] Android Studio
[✓] VS Code
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
Java and javac:
$: java --version
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing)
$: javac --version
javac 11.0.15

Why isn't my app running on an android emulator?

I'm creating a flutter app, and I'm trying to test it for Android. When I open up the emulator, it runs normally, but when I try to run my app, I get this error... Can anyone help solve? It runs perfectly in Xcode on my iPhone, but doesn't seem to run on Android...
Launching lib/main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... FAILURE: Build failed with an exception.
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... * What went wrong:
Running Gradle task 'assembleDebug'... Execution failed for task ':app:processDebugResources'.
Running Gradle task 'assembleDebug'... > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Running Gradle task 'assembleDebug'... > Android resource linking failed
Running Gradle task 'assembleDebug'... /Users/ragz/.gradle/caches/transforms-2/files-2.1/554200784d0157df45da8212b6e09519/play-services-ads-lite-19.7.0/AndroidManifest.xml:27:5-43:15: AAPT: error: unexpected element found in .
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... * Try:
Running Gradle task 'assembleDebug'... 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.
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... * Get more help at https://help.gradle.org
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... BUILD FAILED in 4m 29s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 305.2s
The build failed likely due to AndroidX incompatibilities in a plugin.
The tool is about to try using Jetifier to solve the incompatibility.
Building plugin flutter_tts...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done 87.4s
*********************************************************
WARNING: This version of flutter_tts will break your Android build if it or its dependencies aren't compatible with AndroidX.
See for more information on the problem and how to fix it.
This warning prints for all Android build failures. The real root cause of the error may be unrelated.
*********************************************************
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'flutter_tts'.
SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/Users/ragz/.pub-cache/hosted/pub.dartlang.org/flutter_tts-3.0.0/android/local.properties'.
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 24s
Exception: The plugin flutter_tts could not be built due to the issue
above.
Check if your minSDKVersion 21 in build.gradle.
Here's my flutter doctor run (it seems like nothing is wrong to me, maybe there is? im not sure) -
[✓] Flutter (Channel stable, 2.0.2, on macOS 11.2 20D64 darwin-x64, locale en-GB)
• Flutter version 2.0.2 at /Users/ragz/flutter
• Framework revision 8962f6dc68 (2 weeks ago), 2021-03-11 13:22:20 -0800
• Engine revision 5d8bf811b3
• Dart version 2.12.1
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/ragz/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.4, Build version 12D4e
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• 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
1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.54.3)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.20.0
[✓] Connected device (2 available)
• sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API
30) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome

Problem occurred evaluating root project 'android'. A problem occurred configuring project ':app'

I'm trying to build an apk running flutter build apk --split-per-abi and I'm getting this message:
Note that a week ago this wasn't happening.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\sandbox\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 646
* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> The value for this property cannot be changed any further.
* 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 4s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 5,5s
Gradle task assembleRelease failed with exit code 1
I then ran flutter doctor -v to see if android and flutter were outdated.
After updating and restarting Android Studio I'm getting the same error. Any idea what could be the problem?
C:\sandbox\AndroidStudioProjects\dataps05>flutter doctor -v
[√] Flutter (Channel stable, 1.22.4, on Microsoft Windows [Versión 10.0.18363.1256], locale es-ES)
• Flutter version 1.22.4 at C:\sandbox\flutter
• Framework revision 1aafb3a8b9 (7 weeks ago), 2020-11-13 09:59:28 -0800
• Engine revision 2c956a31c0
• Dart version 2.10.4
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\gabri\AppData\Local\Android\Sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[!] Android Studio (version 4.1.0)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.51.1)
• VS Code at C:\Users\gabri\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.16.0
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.
Do the following for flutter doctor warnings
flutter channel dev
flutter doctor
flutter channel master
flutter doctor
and try this for your problem.

Flutter fails to build android-arm64, android-x64 release versions

I tried building my flutter app as an Android App Bundle, but the build fails for
flutter build appbundle --target-platform android-arm64
and
flutter build appbundle --target-platform android-x64
with exception an exception (same for both commands)
c:\b\s\w\ir\cache\builder\src\third_party\dart\runtime\vm\compiler\backend\il.h: 999: error: unreachable code
Dart snapshot generator failed with exit code -1073740791
Target android_aot_release_android-x64 failed: Exception: AOT snapshotter exited with code -1073740791
build failed.
FAILURE: Build failed with an exception.
* Where:
Script 'D:\Flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 882
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command 'D:\Flutter\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 30s
Running Gradle task 'bundleRelease'...
Running Gradle task 'bundleRelease'... Done 31,1s
Gradle task bundleRelease failed with exit code 1
However, building for android-arm works just fine:
flutter build appbundle --target-platform android-arm
Running flutter doctor -v works just fine.
[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.18363.959], locale de-DE)
• Flutter version 1.17.5 at D:\Flutter\flutter
• Framework revision 8af6b2f038 (4 weeks ago), 2020-06-30 12:53:55 -0700
• Engine revision ee76268252
• Dart version 2.8.4
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
• Android SDK at D:\Android\Android_Development_Requirements\Android\Sdk
• Platform android-29, build-tools 29.0.1
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 46.0.1
• Dart plugin version 192.8052
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
I really can't figure out why, does anybody know what could be the reason for this?
It seems the problem was related to the moor_ffi library, though I couldn't figure out why exactly, however switching to moor_flutter fixed it.

Failed on build on Flutter App "task assembleDebug failed with exit code 1"

I'm using the standard flutter app on Android Studio and when I can't execute flutter pub get and when I execute flutter run I get this exception
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 882
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\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 17s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 18,2s
Exception: Gradle task assembleDebug failed with exit code 1
I already try force upgrade and flutter clean
Flutter Doctor -v
[√] Flutter (Channel stable, v1.17.0, on Windows, locale pt-BR)
• Flutter version 1.17.0 at C:\src\flutter
• Framework revision e6b34c2b5c (4 days ago), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\kaduc\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio1
• Flutter plugin version 45.1.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[!] IntelliJ IDEA Community Edition (version 2019.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.3
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins
[√] VS Code (version 1.44.2)
• VS Code at C:\Users\kaduc\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.10.1
[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
! Doctor found issues in 1 category.
I already uninstall Android Studio IDE and reinstall and I try reinstalling Java JDK but don't chance anything don't know what can I do to fix this issue.
Problem:
Either flutter and dart plugins are not download properly or not configured properly with Android Studio.
Solution:
There is a way to fix this. You can just install/reinstall the Flutter & Dart plugin in android studio by steps below.
1) Open the Android Studio.
2) Open plugin preferences (File > Settings > Plugins on "Windows" & "Linux" or Preferences > Plugins on "macOS").
3) Select Browse repositories, select the Flutter plug-in and click install.
4) Click Yes when prompted to install the Dart plugin.
5) Click Restart when prompted.
6) Run command: sudo chown -R YOUR_USERNAME YOUR_FLUTTER_DIRECTORY
Example: sudo chown -R sanketvekariya /opt/flutter
Some References:
https://github.com/flutter/flutter/issues/21881
https://github.com/flutter/flutter/issues/45528
Flutter plugin not installed error;. When running flutter doctor
FYI:
I have faced same issue earlier and solved by above steps. Hope you solve this soon.:)
I delete the \android\app\build folder, the issue was resolved.
In my case, the problem was that I cloned the project from repo and project was developed by my colleague months ago. So I solved the issue by updating gradle version in gradle-wrapper.properties file and also updating tools.build:gradle in android/build.gradle file.

Categories

Resources