在开发 Flutter 应用程序时,我已经尝试了之前列出的所有修复,但没有任何效果。我相信一切都配置正确并且位于正确的位置,因此我需要帮助找出签名配置仍然抛出此错误的原因。我已经尝试了几个小时寻找另一个解决方案但没有运气。所有内容都拼写正确。错误如下。
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:validateSigningRelease'.
> Keystore file not set for signing config release
key.properties
文件夹位于主android文件夹中,upload-keystore.jks
文件位于android/app
内。
key.properties 是
storePassword=xxxx
keyPassword=xxxx
keyAlias=upload
storeFile=/Users/..../android/app/upload-keystore.jks
并且完整
build.gadle
是
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"
apply plugin: 'com.google.gms.google-services' // Google Services plugin
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'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.fytfeed.fytfeed"
minSdkVersion 23
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 {
signingConfig signingConfigs.release
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
经过一天的头撞墙之后,我想出了这个办法。我的
key.properties
文件夹中文件名开头有一个未知的空格,引发了错误。因此,如果一切正常,请留意随机空间!
或
在Android studio中打开项目“/android”
构建 -> 生成签名包/APK ..
完成步骤...
只需在 key.properties 中选择正确的 JKS 文件路径并重新运行
过了一段时间我意识到我没有使用同一台计算机,并且 key.properties 中的路径可能不同,在这种情况下我使用 Linux 而不是 macbook,所以路径不同,我更改为 Linux 路径并且它起作用了