Flutter 发布了 aab 包,因此出现 NullPointerException 错误。(安卓应用程序包)

son*_*ika 5 release gradle dart flutter android-app-bundle

失败:构建失败并出现异常。

  • 出了什么问题:任务“:app:signReleaseBundle”执行失败。

执行 com.android.build.gradle.internal.tasks.FinalizeBundleTask$BundleToolRunnable java.lang.NullPointerException 时发生失败(无错误消息)

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。

  • 在https://help.gradle.org获取更多帮助

在 24 秒内构建失败运行 Gradle 任务“bundleRelease”...26.2s Gradle 任务bundleRelease 失败,退出代码为 1

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 GradleException("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 plugin: 'kotlin-android'
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 32

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "co.demo.flutter"
        minSdkVersion 21
        multiDexEnabled true
        targetSdkVersion 32
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
      signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
        }
    }

}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//    implementation 'com.android.support:multidex:2.0.1'
    implementation 'com.google.android.gms:play-services-tagmanager:17.0.0'
    implementation "androidx.multidex:multidex:2.0.1"

}
Run Code Online (Sandbox Code Playgroud)

小智 5

我遇到了同样的错误。

就我而言, key.properties 丢失了。

我刚刚将其添加到 [project]/android/key.properties 中

key.properties 的内容是;

storePassword=<password from previous step> (example:  12345678)
keyPassword=<password from previous step> (example:  12345678)
keyAlias=upload
storeFile=/Users/<user name>/upload-keystore.jks (Complete path of upload-keystore.jks 
using "/" not "\")
Run Code Online (Sandbox Code Playgroud)

之后,我运行此命令来构建应用程序包;

flutter build appbundle
Run Code Online (Sandbox Code Playgroud)