如何在Flutter中生成发布apk文件



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

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

keytool -genkey -v -keystore "C:UsersWai Yan Heinupload-keystore.jks" -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

然后我创建了{root}/android/key.properties文件,其中包含以下内容

storePassword=mypassword
keyPassword=mypassword
keyAlias=upload
storeFile=C:UsersWai Yan Heinupload-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:UsersWai Yan HeinDocumentsflutterbinflutter" build apk --split-per-abi

然后我在终端中出现以下错误。

Building with sound null safety 

FAILURE: Build failed with an exception.
* Where:
Build file 'C:UsersWai Yan HeinAndroidStudioProjectsflutter_appandroidappbuild.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

我所做的事情出了什么问题,我该如何解决?

在主.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。这一行将帮助您在没有健全的零安全的情况下运行应用程序。

相关内容

  • 没有找到相关文章

最新更新