49

I got this error when I try to generate a signed apk in the android studio of my flutter app - Process 'command 'E:\Flutter Apps\flutter\bin\flutter.bat'' finished with non-zero exit value 1

I am able to run the app in both emulator and on my device but this error shows up only when I try to build a signed apk.

flutter doctor
[√] Flutter (Channel dev, v1.2.0, on Microsoft Windows [Version 10.0.17763.253], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.3)
[√] VS Code (version 1.30.2)
[√] Connected device (1 available)

• No issues found!

Any way to fix this?

Tried flutter clean

android studio Build > clean project and rebuild project(same error)

I am doing Build > Generated signed apk > apk > release > V1(Jar signature) > Finish to build the app

dheeraj reddy
  • 1,019
  • 2
  • 13
  • 24

26 Answers26

51

I had the same problem after this command flutter upgrade and upgrading from V 1.22 to V 1.27.
Exactly what I did, I went to pubspec.yaml then pub-get & pub-upgrde I found there's many outdated packages then I tried pub-outdated and the AS failed to upgrade it, the it's suggests to me to run this command flutter pub upgrade --major-versions and I saw that it's successfully downloaded and installed outdated packages, Then I do Invalided Caches & restarted AS because I found it's cached about 5GB on C partition, and finally I run the app normally again without any problems.

Dr Mido
  • 2,414
  • 4
  • 32
  • 72
21
  • check if you have any assets is not founded by pubspec.yaml maybe for typo you will get Waring for that after packages get

  • check AndroidX compatibilities in this Flutter app for help show this

Mahmoud Abu Alheja
  • 3,343
  • 2
  • 24
  • 41
  • 3
    Yes, I was assets name problem, now it's working fine – Azhar Ali May 18 '21 at 05:23
  • Yes, that was my issue it was " - assets/icons/svg" i added the '/" at the end like this " - assets/icons/svg/" and it works thanks – Yassine Chilali Jun 23 '22 at 06:27
  • My issue was related to Assets folder of a native plugin I was developing. I just removed the reference from ppubspec.yaml and the problem's gone! Thank you!! – empiresdev Jul 12 '23 at 23:29
13

I solved that trouble with these steps :

  1. flutter clean
  2. delete folder ".gradle" in your projectdir>android>.gradle
  3. delete pubspec.lock
  4. update your gradle to 4.1.0 at projectdir>android>build.gradle
  5. update your gradle distributionUrl to 6.5.1 at projectdir>android>app>gradle>wrapper>gradle-wrapper.properties
  6. restart your IDE
  7. flutter pub get

after that several steps above, running flutter build or flutter run wouldn't be a problem anymore. sometimes step 4 n 5 are not necessary and still solved the problem.

fikr
  • 131
  • 1
  • 3
9

Hi Please check any error in your dart files thats may be cause during error while build

6

For me this command solved:

flutter pub upgrade --major-versions
Stupid
  • 135
  • 1
  • 9
5

Flutter clean worked for me perfectly

Hurman Iqbal
  • 61
  • 1
  • 4
4

You can try reconfiguring the Flutter SDK path in Android Studio's File | Settings | Languages ​​& Frameworks | Flutter.

I have just encountered the same problem and solved it successfully with this method.

胡文涛
  • 71
  • 5
3

Guys there is no such need. The thing is the error is just a exit code. The main error is above in the logs. You can just see it by scrolling above.

3

This solution solved my problem:

My android/build.gradle:

buildscript {
ext.kotlin_version = '1.4.21'
repositories {
    jcenter()
    google()
}

dependencies {
    classpath 'com.android.tools.build:gradle:4.1.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

}

Run flutter clean command in terminal. And delete build folder from android/app path.

Then run your project successfully.

M Karimi
  • 1,991
  • 1
  • 17
  • 34
2

stop the antivirus for some time if installed. it will work.

Bhoomin Naik
  • 402
  • 4
  • 7
  • 1
    Yes, I whitelisted the android studio for deleting / modifying files/folders in Documents folder from antivirus software, and it started working – Anas Nadeem Nov 06 '21 at 20:01
2

I just solved it! It has to deal with the "- assets/images/" line inside pubsec.yaml, I commented it and it works just fine!

ANORAK_MATFLY
  • 345
  • 3
  • 7
2

I encounter the same message and go to Android Studio's setting :

Language & Framework -> Flutter -> Tick "Enable Verbose logging" , and run the build again the check the actual root cause .

In my case the root cause is recursive path in android/build folder, I delete the build folder and problem solved.

2

for me

  1. i deleted the pubspec.lock
  2. flutter clean
  3. flutter pub get
  4. then i figuer out an sdk error i switch my sdk version to 31
1

You probably have errors in your code. Build in verbose mode using command flutter build apk --release -vv and check if there is any error.

SharkFabri
  • 11
  • 1
1

I encountered the same problem. And I run "flutter clean" in the terminal. Then the answer was like this ".packages does not exist. Did you run "flutter pub get" in this directory?". When I run "flutter pub get", it solved my problem.

Xarybdis
  • 157
  • 6
1

In my case nothing worked. Then I deleted the flutter/bin/cache folder and in my command line I ran flutter command that downloads the Dart SDK. After download, setting up the flutter folder path in Flutter SDK Path in Android Studio -> Preferences -> Languages and Frameworks -> Flutter , then click Apply -> Ok, solves the error.

Fahmida
  • 1,050
  • 8
  • 19
1
  1. Go to your root directory of the flutter project by using the cmd command.

  2. write the command flutter clean, then from your android get dependencies to rebuild the cleaned.

if not solved, go to your pubspec.yaml and check your flutter asset indentation. eg

flutter:

  uses-material-design: true

  assets:

   - images/momo.jpg

it works for me absolutely.

钟智强
  • 459
  • 6
  • 17
Motuma
  • 11
  • 1
1

Check if any files in lib folder have

import 'dart.html';
import 'dart.io';

Remove them and try again

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 02 '22 at 11:16
1

I had a problem with google-services.json file. Make sure that the file has the correct package name.

1

It's painful but another simple solution would be to reinstall flutter with the latest version and update the pubspec.yaml file with flutter pub upgrade --major-versions .

After that, perhaps, some code change would be necessary due to the pubspec dependances.

M E S A B O
  • 783
  • 1
  • 11
  • 15
0

I had the same problem after this command flutter upgrade and upgrading from V 2.10.0 to V 3.0.0.

1.To fix this error, I went to C:\Users{username}\flutter.pub-cache\hosted and deleted the pub.dartlang.org folder.

2.After I executed flutter pub get command in my project. this command recreated the previously deleted folder with the packages inside

3.and I built my project again. the error has disappeared

0

In my case I was using Flutter module in native app and because of the syntax error in Flutter module (it could be any error, just look that you have no red-lined files) it wasn't able to compile

Nikita Shadkov
  • 372
  • 3
  • 11
0

It mostly happens for android so In your project folder open the android folder on right clicking goto flutter -> open android module in Android Studio (in the Android module it is easy to understand the exception) try to upgrade what it recommends you and finally run the if the error is still there try to clean the project restart the IDE and run again it worked for me

0

.dart_tool folder delete and then run flutter build apk.

This process help me!

0

In my case, I have configured flavors in my application, and I was running the android.app.main module while writing native code. Instead of having a single main.dart file, I have different main.dart files for different flavors, such as main_dev.dart and main_prod.dart. After adding the main.dart file, everything is working fine.

manoj reddy
  • 64
  • 1
  • 4
-5

open your terminal and run this code

flutter upgrade

hopefully problem solved

AK IJ
  • 492
  • 4
  • 10