Flutter Android - Gradle 任务 bundleRelease 失败,退出代码为 1

Posted

技术标签:

【中文标题】Flutter Android - Gradle 任务 bundleRelease 失败,退出代码为 1【英文标题】:Flutter Android - Gradle task bundleRelease failed with exit code 1 【发布时间】:2020-02-24 06:52:42 【问题描述】:

我正在尝试运行命令“flutter build appbundle --verbose”来生成我的应用程序的 android 版本,但我收到错误“Gradle task bundleRelease failed with exit code 1”。

我还不知道很多关于 gradle 和你对每个包的依赖关系的事情,我已经阅读了一些堆栈溢出的答案,重构了 bundle.properties 文件等等,但没有成功。这是我的构建信息:

flutter build appbundle --verbose 部分输出

:flutter_secure_storage:bundleLibCompileRelease [        ]         
********************************************************* [        ] WARNING: This version of firebase_messaging will break your Android
build if it or its dependencies aren't compatible with AndroidX. [    
]          See xxxxxxx 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. [        ]         
********************************************************* [        ] 90 actionable tasks: 6 executed, 84 up-to-date [ +426 ms] Running
Gradle task 'bundleRelease'... (completed in 11,3s) [   +4 ms]
"flutter appbundle" took 20.362ms.
Gradle task bundleRelease failed with exit code 1

#0      throwToolExit (package:flutter_tools/src/base/common.dart:28:3)
#1      _buildGradleProjectV2 (package:flutter_tools/src/android/gradle.dart:751 :5) <asynchronous
suspension>
#2      buildGradleProject (package:flutter_tools/src/android/gradle.dart:494: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/bui ld_appbundle.dart:47:11)
<asynchronous suspension>
#5      FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/fl utter_command.dart:490:18)
#6      _asyncThenWrapperHelper.<anonymous closure(dart:async-patch/async_patc h.dart:71: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:137:18)
#10     Future._propagateToListeners.handleValueCallback (dart:async/future_impl .dart:678:45)
#11     Future._propagateToListeners (dart:async/future_impl.dart:707:32)
#12     Future._completeWithValue (dart:async/future_impl.dart:522:5)
#13     Future._asyncComplete.<anonymous closure(dart:async/future_impl.dart:5 52:7)
#14     _rootRun (dart:async/zone.dart:1124:13)
#15     _CustomZone.run (dart:async/zone.dart:1021:19)
#16     _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#17     _CustomZone.bindCallbackGuarded.<anonymous closure(dart:async/zone.dar t:963:23)
#18     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#19     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#20     _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116: 13)
#21     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dar t:173:5)

Android(父级)build.gradle:

buildscript 
  repositories 
    google()
    jcenter()
  

  dependencies 
    classpath 'com.android.tools.build:gradle:3.5.1'
    classpath 'com.google.gms:google-services:4.0.1'
  


allprojects 
  repositories 
    google()
    jcenter()
  


rootProject.buildDir = '../build'
subprojects 
  project.buildDir = "$rootProject.buildDir/$project.name"

subprojects 
  project.evaluationDependsOn(':app')


task clean(type: Delete) 
  delete rootProject.buildDir

//solving error
subprojects 
  project.configurations.all 
    resolutionStrategy.eachDependency  details ->
      if (details.requested.group == 'com.android.support'
              && !details.requested.name.contains('multidex') ) 
        details.useVersion "27.1.0"
      
    
  

应用(子)build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) 
    localPropertiesFile.withReader('UTF-8')  reader ->
        localProperties.load(reader)
    


def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) 
    throw new Exception("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")


def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) 
    flutterVersionCode = '1'


def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) 
    flutterVersionName = '1.0'


apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) 
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))


android 
    compileSdkVersion 28
    buildToolsVersion "28.0.3"

/*    lintOptions 
        disable 'InvalidPackage'
    */

    defaultConfig 
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "br.com.xxxx.xxxx"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    
    signingConfigs 
        release 
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file('key.jks')
            storePassword keystoreProperties['storePassword']
        
    
    buildTypes 
        release 
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources false
            //useProguard true
            //proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        
    


flutter 
    source '../..'


dependencies 
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.0.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    androidTestImplementation 'androidx.test:runner: 1.2.0'
    implementation 'com.google.firebase:firebase-core:17.0.0'
    implementation 'com.google.firebase:firebase-iid:17.1.1'


apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

Flutter / Dart pubspec.yaml

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for ios style icons.
  cupertino_icons: ^0.1.2
  firebase_messaging: ^5.1.6
  carousel_pro: ^1.0.0
  http: ^0.12.0+2
  fluro: ^1.5.0
  share: ^0.6.1+1
  transparent_image: ^1.0.0
  photo_view: ^0.4.2
  carousel_slider: ^1.3.0
  intl: ^0.15.8
  expandable: ^3.0.0+1
  url_launcher: ^5.1.2
  keyboard_avoider: ^0.1.2
  flutter_secure_storage: ^3.2.1+1
  keyboard_visibility: ^0.5.6
  fluttertoast: ^3.1.0
  image_picker: 0.6.0+17
  image_cropper: ^1.1.0
  shared_preferences: 0.5.3+4
  cached_network_image: ^1.1.0
  rxdart: ^0.22.2
  dio: 3.0.3
  path: 1.6.4
  uuid: 2.0.2
  flutter_app_badger: ^1.0.3+2
  badges: ^1.0.0
  flutter_local_notifications: ^0.8.4
  #device_id: ^0.2.0

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

大家有什么解决这个问题的建议吗?

我也尝试过迁移到 AndroidX,但没有成功。

【问题讨论】:

将这些 android.useAndroidX=trueandroid.enableJetifier=true 添加到 android/gradle.properties。让我知道这是否有效。 也许你需要看看这个帖子https://***.com/questions/49695393/flutter-build-apk-create-old-version-app 嗨@ArashMohammadi,我已经完成了..."org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true #extra-gen-snapshot-options=--obfuscate android.enableR8=false " @HaironChaviano,它看起来不是我需要的:/ 您找到解决方案了吗? 【参考方案1】:

我今天也遇到了这个问题。我部署了两个应用程序,具有不同版本的 gradle 版本。尝试这个。在android/build.gradle 尝试使用com.android.tools.build:gradle:3.3.1,似乎gradle 3.5 给flutter 成功构建appbundle 带来了问题。

但如果你阅读here,appbundle 实际上是在build/app/outputs/bundle/&lt;build-type&gt; 中创建的

【讨论】:

【参考方案2】:

这是一个小问题,运行“Flutter clean”,然后运行“Flutter build appbundle”或“Flutter build apk”。

这应该可以解决问题

【讨论】:

嘿,这不起作用我试了两次..请建议任何其他方法

以上是关于Flutter Android - Gradle 任务 bundleRelease 失败,退出代码为 1的主要内容,如果未能解决你的问题,请参考以下文章

Flutter Android Build Gradle错误配置根项目'android'?

运行flutter应用程序时android studio中的gradle错误

Android Studio gradle 问题中的 Flutter 项目

Flutter Android Studio 不断出现 gradle 错误?

解决Flutter升级后,flutter run 卡在gradle build running的问题

android studio/flutter 无限说“正在初始化 gradle”