#android #flutter #flutter-apk
Вопрос:
Я создаю APK-файл для своего приложения Flutter. Я следую этой статье, 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
Что не так с тем, что я сделал, и как я могу это исправить?
Комментарии:
1. Вы определили
key.properties
вbuild.gradle
файле уровня приложения?2. вы добавили конфигурацию в файл gradle. следуйте этому сообщению : flutter.axuer.com/docs/deployment/android
3. Привет, да, я так и сделал. Это как раз перед разделом Android.
Ответ №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
. Эта строка поможет вам запустить ваше приложение без звуковой нулевой безопасности.
Комментарии:
1. Как, как? Я должен добавить комментарии?