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

标签 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 但没有成功。

最佳答案

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

这应该可以解决问题

关于android - Flutter Android - Gradle 任务 bundleRelease 失败,退出代码为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58600540/

相关文章:

Android - 增加警报对话框中按钮的大小

flutter - 自定义 Clipper Bezier 曲线 Flutter

dart - 使用 BottomNavigationBar 时禁用滑动手势

android - 使用 TextInputLayout.OutlinedBox 样式的 Material 设计 Spinner

Android SDK Manager 安装特定版本的 NDK Bundle

android - textview 中的显示计时器包含 android 中的天、小时、分钟和秒

gradle - 在 Gradle 中为复制任务指定输出文件

安卓 :app:transformClassesWithJarMergingForDebug FAILED - ZipException: duplicate entry

android - 资源 'attr/tint' 的重复值

android - 带有 Workmanager 插件的后台任务在 flutter 中不起作用