Flutter选择错误的密钥库路径并给出错误的key.jks找不到

Gud*_*guy 2 dart flutter

我遵循了Flutter官方网站上的所有步骤,并认为我已正确完成了所有操作,但是在构建时无法找到密钥库文件。

这是我显示的错误消息,而不是错误的路径 D:\flutterapps\testapp\key.jks

PS D:\flutterapps\testapp> flutter build apk
Initializing gradle...                                       1.3s
Resolving dependencies...                                    4.3s
Gradle task 'assembleRelease'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:validateSigningRelease'.
> Keystore file 'D:\flutterapps\testapp\android\app\ D: lutterappspublishkey.jks' not found for signing config 'release'.

* 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 4s
Gradle task 'assembleRelease'... Done                        5.3s
Gradle task assembleRelease failed with exit code 1
PS D:\flutterapps\testapp>
Run Code Online (Sandbox Code Playgroud)

小智 39

在 Windows 上,您必须使用 2 个反斜杠来表示路径分隔。在你的key.properties,你应该有这样的东西:

storeFile=D:\\flutterapps\\testapp\\key.jks
Run Code Online (Sandbox Code Playgroud)

你不需要将你的key.jks文件复制到你的 flutter 项目中。

  • 在 Windows 中使用正斜杠。 (2认同)

Gud*_*guy 7

修改了key.properties文件

storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=key.jks
Run Code Online (Sandbox Code Playgroud)

代替这个

storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=D:\flutterapps\testapp\key.jks
Run Code Online (Sandbox Code Playgroud)

并将key.jks移至D:\ flutterapps \ testapp \ android \ app \ key.jks

因为此路径在终端内部错误显示

谢谢大家

  • 如果您要在应用程序中移动密钥(不推荐),请不要忘记在 .gitignore 文件中添加一行 `key.jks` ,因为不应将此文件上传到任何公共存储库。您还需要 \\ 而不是上面提到的 \ 。 (5认同)
  • 这不是问题的原因。真正的原因是windows的反斜杠。keytool 认为这些是转义字符并忽略它们。您可以执行此 D:\\flutterapps\\testapp\\key.jks 或此 D:/flutterapps/testapp/key.jks 来避免该问题。 (3认同)

bla*_*eil 5

它在您的build.gradle. 插入这个:

signingConfigs {
release {
    keyAlias keystoreProperties['keyAlias']
    keyPassword keystoreProperties['keyPassword']
    storeFile file(keystoreProperties['storeFile'])
    storePassword keystoreProperties['storePassword']
  }
}
Run Code Online (Sandbox Code Playgroud)

并在你的 android{} 上面调用它:

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
Run Code Online (Sandbox Code Playgroud)

key.properties 文件(应该位于你的 android 根文件夹中)应该包含以下内容:

storePassword=12345
keyPassword=12345
keyAlias=key
storeFile=/Users/me/somekey.jks
Run Code Online (Sandbox Code Playgroud)