问题
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?
回答1:
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):
- /android/gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
/android/build.gradle:
buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' } }
回答2:
I commented list of APIs in app.gradle and then it works:
android {
splits {
abi {
//include "x86", "x86_64", "armeabi", "armeabi-v7a", "arm64-v8a"
}
}
}
回答3:
There is a multitude of reasons for which you might encounter a frustrating problem like Gradle build failed to produce an Android bundle package
.
As of @Tam Tam Tam's answer, first try to update your gradle and android gradle plugin to a latest version.
If that does not fix your problem, then try to disable all the different architectures and set universalApk
to false
in your android/app/build.grade
in splits section. Put something like this:
splits {
abi {
enable true
reset()
// include 'x86', 'armeabi-v7a', 'x86_64'
universalApk false
}
}
This suggestion was provided here: https://github.com/flutter/flutter/issues/27462#issuecomment-507229131
It happens because gradle generates the apk following a convention, eg, app-<architecture-name>.apk
, which is not understandable by flutter, it expects apk names in another format, eg, simply app.apk
. Disabling all different architectures name bring them to a common understanding :)
If that is also not work, then try to remember if you change your package name com.example.packagename
to something your own personal like com.mywebsite.packagename
. If you have done it, then you probably changed it everywhere needed, for example, in build.gradle
s and AndroidManifest.xml
but you might forgot to change it in your java (or kotlin class).
To make your new package name works, you also have to change the package name in src/main/java/com/mywebsite/packagename/MainActivity.java
(in case of kotlin, it's src/main/kotlin/com/mywebsite/packagename/MainActivity.kt
)
I hope this helps.
回答4:
For me, migrating to AndroidX fixed everything:
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
回答5:
For me, I had signingConfig signingConfigs.debug line missing in my release config of app's build.gradle
file. But error I was getting is the same "Gradle build failed to produce an Android bundle package".
android {
...
buildTypes {
release {
signingConfig signingConfigs.debug
...
}
}
}
回答6:
For me changing my gradle version as following line solved the issue. (I was using a higher version)
android/build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
}
回答7:
Here is my senario:
I'm using a remote machine from CI to sign apk with release sign config.
So I removed buildTypes.release.signConfig
in build.gradle
like this:
buildTypes {
release {
// signingConfig signingConfigs.release
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
This makes the name of the output apk change to app-release-unsigned.apk
but flutter expects app-release.apk
, which leads to Gradle build failed to produce an Android bundle package.
After adding signingConfig signingConfigs.release
back the problem was solved.
来源:https://stackoverflow.com/questions/55990485/how-to-fix-gradle-build-failed-to-produce-an-android-bundle-package-in-flutte