提问人:Hammas Ali 提问时间:11/9/2022 更新时间:11/10/2022 访问量:413
任务“:app:packageRelease”执行失败。无法恢复密钥
Execution failed for task ':app:packageRelease'. Cannot recover key
问:
我正在使用已创建的密钥库文件创建发布版本。将文件放在 android/app/AlZarooniKS 中。从 android studio 执行构建 apk 时,它会在 assembleRelease 中出现错误,但在 assembleDebug 上工作正常。我收到了以下异常。
* What went wrong:
Execution failed for task ':app:packageRelease'.
> A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
> com.android.ide.common.signing.KeytoolException: Failed to read key AlZarooniKS from store "/Users/hammas/Desktop/parking/android/app/AlZarooniKS": Cannot recover key
* 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 15s
Running Gradle task 'assembleRelease'... 16.6s
Gradle task assembleRelease failed with exit code 1
我的 key.properties 文件
storePassword=xxx
keyPassword=xxx
keyAlias=AlZarooniKS
storeFile=/Users/hammas/Desktop/parking/android/app/AlZarooniKS
这是 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 FileNotFoundException("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'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
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 localProperties.getProperty('flutter.compileSdkVersion').toInteger()
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 {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.quaidtech.emirates_parking"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion flutter.targetSdkVersion
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 {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
答:
0赞
Mohamed Gawdat
11/9/2022
#1
- 请确保使用无效的密钥名称和密码
- 在 key.property 中使用以 “” 结尾的密钥路径
.jks
- 如果失败,请使用新别名创建另一个发布密钥
评论
0赞
Hammas Ali
11/10/2022
实际上,我已经从另一台电脑上用这个文件进行了构建。现在将项目转移到导致此错误的新项目。在旧电脑上,它工作正常。
0赞
Hammas Ali
11/10/2022
#2
降级 kotlin 版本和 gradle 插件在 flutter clean & flutter pub get && flutter run 之后为我做到了
评论