我正在为我的Flutter应用程序生成APK文件。我正在遵循这篇文章,https://flutter.dev/docs/deployment/android。但是当我生成apk文件时,它给了我这个错误。
首先,我运行以下命令生成keystore文件。
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我的所作所为出了什么问题,我如何才能修复它?
发布于 2021-06-18 19:04:26
将以下行添加到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。这一行将帮助您在没有声音空安全的情况下运行应用程序。
https://stackoverflow.com/questions/68033789
复制相似问题