我遵循了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 项目中。
修改了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
因为此路径在终端内部错误显示
谢谢大家
它在您的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)