0

我正在为我的 Flutter 应用程序生成一个 APK 文件。我正在关注这篇文章,https: //flutter.dev/docs/deployment/android 。但是当我生成apk文件时它给了我错误。

首先,我生成运行以下命令的密钥库文件。

keytool -genkey -v -keystore "C:\Users\Wai Yan Hein\upload-keystore.jks" -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

然后我创建了具有以下内容的 {root}/android/key.properties 文件

storePassword=mypassword
keyPassword=mypassword
keyAlias=upload
storeFile=C:\Users\Wai Yan Hein\upload-keystore.jks

我更新了 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 30

    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 "com.example.flutter_app"
        minSdkVersion 16
        targetSdkVersion 30
        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
        }
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

然后我运行以下命令在项目根文件夹中生成 apk 文件。

"C:\Users\Wai Yan Hein\Documents\flutter\bin\flutter" build apk --split-per-abi

然后我在终端中收到以下错误。

 Building with sound null safety 


FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Wai Yan Hein\AndroidStudioProjects\flutter_app\android\app\build.gradle' line: 31

* What went wrong:
A problem occurred evaluating project ':app'.
> Malformed \uxxxx encoding.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                      25.4s
Gradle task assembleRelease failed with exit code 1

我所做的有什么问题,我该如何解决?

4

1 回答 1

0

将以下行添加到 main.dart 文件的顶部

// @dart=2.9
//TODO uncomment it, when all the packages moved to the null safety.
//It helps to generate the signed apk.

看起来,您的某些库pubspec未迁移到null-safety. 此行将帮助您在没有健全的 null 安全性的情况下运行您的应用程序。

于 2021-06-18T11:04:26.173 回答