我是 flutter 的新手,我正在嘗試運行我的第一個專案,而無需對演示應用程式的源代碼進行任何更改。但我不斷收到以下錯誤:
Launching lib\main.dart on SM A115F in release mode...
Running Gradle task 'assembleRelease'...
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\METRO\StudioProjects\helloworld\android\app\build.gradle' line: ??
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'keystoreProperties' for SigningConfig_Decorated{name=release, storeFile=null, storePassword=null, keyAlias=null, keyPassword=null, storeType=pkcs12, v1SigningEnabled=true, v2SigningEnabled=true, enableV1Signing=null, enableV2Signing=null, enableV3Signing=null, enableV4Signing=null} of type com.android.build.gradle.internal.dsl.SigningConfig.
* 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 5s
Exception: Gradle task assembleRelease failed with exit code 1
即使我只是嘗試運行專案,我也嘗試了從升級 gradle 到生成密鑰庫的所有方法,這是我的 app\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'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.helloworld"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName.toString()
}
signingConfigs{
release {
keyAlias keystoreProperties['key']
keyPassword keystoreProperties['key password']
storeFile keystoreProperties['C:\\Users\\METRO\\key.jks'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['store password']
}
}
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
}
}
}
flutter {
source '../..'
}
if (project.hasProperty("MyProject.signing")
&& new File(project.property("MyProject.signing") ".gradle").exists()){
apply from: project.property("MyProject.signing") ".gradle"
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()){
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
這是我的 keystore.properties 檔案:
storePassword = store password
keyPassword = key password
keyAlias = key
storeFile = C:\\Users\\METRO\\key.jks
注意:android studio 將 storePassword、keyPassword、keyAlias 前面的警告高亮顯示為未使用的屬性。這是問題嗎?如果是,如何解決?請幫忙。
uj5u.com熱心網友回復:
您似乎錯誤地配置了 app\build.gradle 檔案并在 keystore.properties 上使用了雙反斜杠。
將此添加到 localProperties 的末尾而不是該檔案的底部。
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
改變你的
signingConfigs{
release {
keyAlias keystoreProperties['key']
keyPassword keystoreProperties['Kha128256512$']
storeFile keystoreProperties['C:\\Users\\METRO\\key.jks'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['Kha128256512$']
}
到
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ?
file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
并在終端上運行它
keytool -genkey -v -keystore c:\Users\YOUR_PREFERRED_LOCATION\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias 上傳
并確保您在 key.properties 檔案中像這樣設定您的位置
storeFile=c:/Users/YOUR LOCATION/upload-keystore.jks
uj5u.com熱心網友回復:
按照步驟操作,您將擺脫問題:
Flutter 簽署應用程式
您可能也錯誤地配置了檔案和憑據。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322947.html
標籤:扑 安卓工作室 等级 android-keystore
上一篇:如何在沒有多專案的情況下使用AndroidGradle
下一篇:如何修復gradle:沒有簽名
