Flutter Android-Gradle任务捆绑包发布失败,退出代码为1

时间:2019-10-29 01:56:03

标签: android gradle flutter android-gradle-plugin

我正在尝试运行命令“ 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,但没有成功。

2 个答案:

答案 0 :(得分:0)

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

但是,如果您阅读here,则实际上是在build/app/outputs/bundle/<build-type>中创建了该附件

答案 1 :(得分:0)

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

应该可以解决问题