How to fix "Gradle build failed to produce an Android bundle package." in Flutter

user2338826 picture user2338826 · May 5, 2019 · Viewed 8.2k times · Source

On running flutter build appbundle I am getting the following error: Gradle build failed to produce an Android bundle package.

When running in verbose mode this is what I additionally get:

#0      throwToolExit (package:flutter_tools/src/base/common.dart:24:3)
#1      _buildGradleProjectV2 (package:flutter_tools/src/android/gradle.dart:585:7)
<asynchronous suspension>
#2      buildGradleProject (package:flutter_tools/src/android/gradle.dart:331:14)
<asynchronous suspension>
#3      buildAppBundle (package:flutter_tools/src/android/app_bundle.dart:43:10)
<asynchronous suspension>
#4      BuildAppBundleCommand.runCommand (package:flutter_tools/src/commands/build_appbundle.dart:43:11)
<asynchronous suspension>
#5      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:545:18)
#6      _asyncThenWrapperHelper.<anonymous closure> (dart:async/runtime/libasync_patch.dart:77:64)
#7      _rootRunUnary (dart:async/zone.dart:1132:38)
#8      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#9      _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
#10     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
#11     Future._propagateToListeners (dart:async/future_impl.dart:668:32)
#12     Future._complete (dart:async/future_impl.dart:473:7)
#13     _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#14     _AsyncAwaitCompleter.complete.<anonymous closure> (dart:async/runtime/libasync_patch.dart:33:20)
#15     _rootRun (dart:async/zone.dart:1124:13)
#16     _CustomZone.run (dart:async/zone.dart:1021:19)
#17     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
#18     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#19     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#20     _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#21     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)

I am on Flutter stable channel v1.2.1.

I can build an apk without a problem though. I can also build an appbundle from another Flutter project.

Based on the error messages above how would you start to find the issue? What might be the problem here?

Answer

Tam Tam Tam picture Tam Tam Tam · May 21, 2019

I have similar issue with the same error messages. (Build Release APK successfully but failed to build app bundle) The solution that works for me is to upgrade the Android Gradle Version. Below are the config that works for me (You may upgrade to the latest version also):

  1. /android/gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

  1. /android/build.gradle:

    buildscript {
        repositories {
           google()
           jcenter()
          }
    
        dependencies {
           classpath 'com.android.tools.build:gradle:3.2.1'
        }
    }