配置Gradle签名后执行flutter build appbundle出现编码错误求助
解决Flutter打包AppBundle时的"Malformed \uxxxx encoding"错误
按照Flutter官方文档完成Gradle签名配置后,执行flutter build appbundle命令时出现编码错误,提示Malformed \uxxxx encoding,指向android/app/build.gradle第51行。
错误输出
PS C:\Dosyalar\Yazilim\Flutter\Deprem SafeArea\safearea> flutter build appbundle Building with sound null safety FAILURE: Build failed with an exception. * Where: Build file 'C:\Dosyalar\Yazilim\Flutter\Deprem SafeArea\safearea\android\app\build.gradle' line: 51 * 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 1s Running Gradle task 'bundleRelease'... 2.487ms Gradle task bundleRelease failed with exit code 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" android { compileSdkVersion 33 ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { applicationId "visible" minSdkVersion 23 targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } signingConfigs { debug { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] } } buildTypes { debug { signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
问题原因
这个错误是因为Windows路径中的单反斜杠\被Gradle当成了Unicode转义字符的起始,而后续字符不符合\uxxxx的编码格式,导致解析失败。问题出在key.properties文件里的storeFile路径配置。
解决步骤
- 打开项目根目录下的
key.properties文件 - 找到
storeFile这一行,修改路径分隔符:- 错误写法(单斜杠):
storeFile=C:\Dosyalar\Yazilim\Flutter\Deprem SafeArea\safearea\android\upload-keystore.jks - 正确写法1(改用正斜杠):
storeFile=C:/Dosyalar/Yazilim/Flutter/Deprem SafeArea/safearea/android/upload-keystore.jks - 正确写法2(双反斜杠转义):
storeFile=C:\\Dosyalar\\Yazilim\\Flutter\\Deprem SafeArea\\safearea\\android\\upload-keystore.jks
- 错误写法(单斜杠):
- 也可以使用相对路径(推荐),如果签名文件放在
android目录下,直接写:storeFile=./upload-keystore.jks - 保存文件后,重新执行
flutter build appbundle命令
内容的提问来源于stack exchange,提问作者Emir Bolat
相关产品推荐
相关产品推荐

