dart Flutter选择错误的密钥库路径并给出错误密钥,未找到jks

camsedfj  于 2023-05-20  发布在  Flutter
关注(0)|答案(7)|浏览(301)

我遵循了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>
sbtkgmzw

sbtkgmzw1#

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

storeFile=D:\\flutterapps\\testapp\\key.jks

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

brgchamk

brgchamk2#

修改的key.properties文件

storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=key.jks

而不是这个

storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=D:\flutterapps\testapp\key.jks

并将key.jks移动到D:\flutterapps\testapp\android\app\key.jks
因为此路径在终端内显示错误
谢谢大家。

yzckvree

yzckvree3#

它就在您build.gradle中调用它的任何地方。插入以下内容:

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

然后在你的android上面调用这个{}:

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

key.properties文件(应该在你的Android根文件夹中)应该有:

storePassword=12345
keyPassword=12345
keyAlias=key
storeFile=/Users/me/somekey.jks
rta7y2nd

rta7y2nd4#

对我来说是的我忘记在build.gradle文件中将signingConfig更改为singingConfigs.release

buildTypes {
        release {
           //CHANGE THIS TO RELEASE
            signingConfig signingConfigs.debug
        }
    }
z9smfwbn

z9smfwbn5#

正在构建.gradle
更换

def keystorePropertiesFile = rootProject.file('key.properties')

def keystorePropertiesFile = rootProject.file('app/key.properties')
n53p2ov0

n53p2ov06#

我也遇到了同样的问题,我的道路上也有引号。
在www.example.com中key.properties,更改
storeFile="D:\\mypath\\tokeystore\\key.jks"

storeFile=D:\\mypath\\tokeystore\\key.jks

gzjq41n4

gzjq41n47#

我的Flutter应用程序也遇到了同样的问题,下面是我在Mac上解决这个问题的方法。
1.确保您的key.properties文件位于android目录中,因此路径应为android/key.properties
1.您的key.properties文件应具有以下结构:

storePassword=Yourpasswordgoeshere 
keyPassword=Yourpasswordgoeshere
keyAlias=key
storeFile=/Users/yourUsername/Apps/yourappname/android/app/upload-keystore.jks

1.如果你不确定你的keyAlias密钥是什么,打开你的终端并运行这个命令keytool -list -v -keystore /path/to/your/keystore,用运行keytool -genkey时提供的实际密钥库路径替换/path/to/your/keystore。命令。要查找keyAlias,请搜索
-alias
或者,如果您使用Android Studio生成密钥库,请转到Build>Generate Signed Bundle/APK,选择APK,然后在那里找到密钥库路径、密码和别名。
1.打开位于android>app>build.gradle的build.gradle文件。确保已在android块上方和apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle":下方添加了以下代码

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
 android {..............// IGNORE THIS LINE

1.在defaultConfig块中,检查是否还添加了以下代码:

signingConfigs {
 release {
     keyAlias keystoreProperties['keyAlias']
     keyPassword keystoreProperties['keyPassword']
     storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
     storePassword keystoreProperties['storePassword']
    }
}
 buildTypes {
    release {
     signingConfig signingConfigs.release
     minifyEnabled true
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
   }
 }

minifyEnabled和proguardFiles键用于代码收缩和模糊处理,并且是可选的。
1.运行flutter clean && flutter pub get
1.运行flutter build appbundle。如果构建过程成功完成,您将看到✓ Built build/app/outputs/bundle/release/app-release.aab。此路径指示应用程序包在Flutter项目中的存储位置。

相关问题