Flutter Android Studio 错误:无法获取未知属性“keystoreProperty”

2023-12-20

我是 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 前面的警告突出显示为未使用的属性。难道这就是问题所在?如果是的话如何解决?请帮忙。


您似乎错误配置了 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$']
    }

to

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 upload

并确保在 key.properties 文件中设置您的位置

storeFile=c:/Users/YOUR LOCATION/upload-keystore.jks

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Flutter Android Studio 错误:无法获取未知属性“keystoreProperty” 的相关文章

随机推荐

  • IE11 阻止 ActiveX 运行

    我们的网络浏览器插件在 IE9 和 IE10 中工作正常 但在 IE11 中该插件既不被识别为附加组件 也不被允许运行 就好像IE11不再支持ActiveX一样 当然有解决方法 但是我们需要改变什么 注意 这个问题是作为插件的开发者提出的
  • Phonegap 相机返回带有黑条的照片

    我正在使用 Phonegap 3 4 当我在 iPhone 上拍摄风景照片时 我得到的照片顶部和底部有黑条 这是我的相机配置选项 var cameraOptions correctOrientation true quality 90 de
  • 如何更改电子邮件的 html5 模式错误消息

    Html5 required 属性通常会添加错误消息 请填写此字段 并且可以使用以下代码轻松更改它 oninvalid setCustomValidity Custom text in another language oninput se
  • 如何将记录插入到sql server express数据库表中?

    我正在尝试将文本框值插入到名为的数据库表中site list The site list表包含两列id and site name id设置为自动递增 这是我正在尝试的代码 执行时没有错误 但数据未显示在表中 SqlConnection c
  • 如何验证 Google Cloud Endpoints 服务 URL 的所有权?

    我已经设置了 Google Cloud Endpoints 项目 并且可以调用 http https 请求 Endpoints 为我提供了可以使用的 MY API endpoints MY PROJECT cloud goog 域名 我正在
  • Spark Dataframe 在性能上比 Pandas Dataframe 有何优势? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 谁能解释一下 Spark Dataframes 在执行时间方面比 Pandas Dataframes 更好 我正在处理中等数量的数据并
  • didAddAnnotationViews 不适用于 MKMapView

    我一直在研究 MKMapView 并尝试了解 MKMapViewDelegate 系统的工作原理 到目前为止 我没有运气在添加当前位置标记时调用 didAddAnnotationViews 我已将我的应用程序委托设置为实现 MKMapVie
  • 导入到 .pch 文件和 .h 文件顶部?

    我是 obj c 的新手 我注意到 pch 文件用于包含整个 x code 项目中的文件 但是相同的文件也包含在一些 h 文件的顶部 例如 import 什么是如果它已经包含在 pch 文件中 是否需要在 h 文件的顶部再次导入它 预编译头
  • 了解 Laravel 5.2 上的队列和调度程序

    我正在尝试如何在 Laravel 上编写作业 根据 Laravel 文档 我创建了一个使用 mail queue 发送电子邮件的简单作业 我还添加了一个 cron 作业 该作业每分钟调用一次调度程序 而调度程序又每 5 分钟运行一次该作业
  • 显示 Scala 表达式的推断类型

    如何查看 Scala 编译器为表达式等推断的类型 我有一些具有复杂类型推断和隐式转换的代码 仅通过阅读代码很难看出发生了什么 我尝试过添加 scalacOptions in Compile Xprint types 在build sbt中
  • 关于fork和execve系统调用

    据说fork系统调用创建调用进程的克隆 然后 通常 子进程发出execve系统调用来更改其映像并运行新进程 为什么要分两步走 顺便说一句 什么是execve代表 采取两步走的原因是灵活性 在这两个步骤之间 您可以修改新执行的程序将继承的子进
  • 我们如何更改标签中的行?

    我有一个标签 在设置文本时我想更改行 例如 String str first line n Secondline JLabel label setText str 我尝试了上面的代码 但它不起作用 如何更改字符串中的行 Swing 不使用经
  • 获取自定义用户控件中声明的事件的所有事件处理程序

    我正在尝试编写一个通用函数 给出对控件 组件的引用以及在其类上声明的事件的名称 它应该能够检索 通过反射 当前为指定事件名称注册的所有事件处理程序 我遇到的第一个也是主要问题 已解决 因此您可以忽略本段 是我在 StackOverflow
  • Perl 中“0 but true”是什么意思?

    有人能解释一下 Perl 中字符串 0 but true 的确切含义吗 据我了解 它在整数比较中等于零 但在用作布尔值时计算结果为 true 它是否正确 这是语言的正常行为还是解释器中将其视为特殊情况的特殊字符串 这是语言的正常行为 引用p
  • 如何在 PHP 中从客户端设置自定义 $_SERVER 变量

    根据这篇文章 哪些 SERVER 变量是安全的 https stackoverflow com questions 6474783 which server variables are safe我见过的另一个例子是 客户端似乎能够设置自定义
  • HTML5 地理定位高度

    我正在为我正在从事的项目使用 html5 地理定位 api 纬度和经度报告正确 但高度始终返回为 空 测试设备是 Nexus 4 和 5 还有其他人遇到过类似问题吗 绝对地 这似乎是一个可能特定于浏览器的问题 由于我在 iPhone 和 A
  • gcc 生成的 x86_64 汇编代码中的 xorl %eax, %eax

    我对组装完全是个菜鸟 只是四处看看发生了什么 无论如何 我写了一个非常简单的函数 void multA double x long size long i for i 0 i
  • HTTP 的 BPF 是什么?

    定义可见here http en wikipedia org wiki Berkeley Packet Filter 候选人的答案可能是tcp and dst port 80 但是可以tcp and dst port 80保证它是HTTP流
  • Visual Studio 类图未显示关系

    当我定义类属性而不使用字段 使用 C 3 0 启用 时 类图未显示我的一对一 多关系 不过 继承在图中是可见的 有没有办法来解决这个问题 当您右键单击字段或属性时 您可以选择显示为关联或显示为集合关联
  • Flutter Android Studio 错误:无法获取未知属性“keystoreProperty”

    我是 flutter 新手 我正在尝试运行我的第一个项目 而不对演示应用程序的源代码进行任何更改 但我不断收到以下错误 Launching lib main dart on SM A115F in release mode Running