无法在 flutter 中构建 apk,因为在 android/app/build.gradle 中出现错误

问题描述 投票:0回答:1

当我尝试运行 flutter build apk 时,我无法生成 apk 并且在构建 gradle 中显示错误。

我得到的错误:- 失败:构建失败并出现异常。

  • 出了什么问题: 任务“:app:packageRelease”执行失败。

执行 com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable 时发生故障 SigningConfig“release”缺少必需的属性“storeFile”。

  • 尝试:

使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获得更多日志输出。 使用 --scan 运行以获得完整的见解。

1m 5s 内构建失败 运行 Gradle 任务“assembleRelease”... 66.5s Gradle 任务 assembleRelease 失败,退出代码为 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"
apply plugin: 'com.google.gms.google-services'

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace "com.example.tis_root01"
compileSdkVersion flutter.compileSdkVersion
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.example.tis_root01"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion Math.max(flutter.minSdkVersion,24)
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

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"
}
flutter firebase gradle apk
1个回答
0
投票

检查项目的 Android 文件夹中是否有

key.properties
文件。

我认为这个错误与其相关,因为它是在其中指定的

SigningConfig "release" is missing required property "storeFile".

并确保使用与

variable
文件内的签名配置中写入的相同
build.gradle
名称。

用这个

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}

并确保你有

keyAlias
=您键入别名

keyPassword
= 您的密钥密码

storeFile
= 密钥存储文件路径

storePassword
= 您密钥存储密码

检查您的

key.properties
文件中是否包含所有这些内容

© www.soinside.com 2019 - 2024. All rights reserved.