Reputation: 1031
I followed all the steps on the Flutter official site and thought I'd done everything correctly but it is failing to locate the keystore file when I build it.
This is the error message I get showing it taking wrong path instead of
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>
Upvotes: 29
Views: 53106
Reputation: 2635
I experienced the same issue with my Flutter app and here's how I solved it on my Mac.
Ensure that your key.properties
file is located inside the android directory, so the path should be android/key.properties
.
Your key.properties file should have the following structure:
storePassword=Yourpasswordgoeshere
keyPassword=Yourpasswordgoeshere
keyAlias=key
storeFile=/Users/yourUsername/Apps/yourappname/android/app/upload-keystore.jks
If you're unsure what your keyAlias key is, open your terminal and run this command keytool -list -v -keystore /path/to/your/keystore
, replacing /path/to/your/keystore with the actual keystore path which is provided when you run the keytool -genkey.. command. To find your keyAlias, search for
-alias
.
Alternatively, if you used Android Studio to generate your keystore, go to Build>Generate Signed Bundle/APK, select APK and the key store path, password and alias can be found there.
Open your build.gradle file located at android>app>build.gradle
. Make sure you have added the following code above the android
block and below
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
Within the defaultConfig block, check that you have also added the following code:
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'
}
}
The minifyEnabled and proguardFiles keys are used for code shrinking and obfuscation and are optional.
flutter clean && flutter pub get
flutter build appbundle
. If the build process completes successfully, you will see ✓ Built build/app/outputs/bundle/release/app-release.aab
. This path indicates where the app bundle is stored within your Flutter project.Upvotes: 2
Reputation: 640
I was having the same issue, I ended up having quotes around my path.
In key.properties, change
storeFile="D:\\mypath\\tokeystore\\key.jks"
to
storeFile=D:\\mypath\\tokeystore\\key.jks
Upvotes: 0
Reputation: 76
In build.gradle
Replace
def keystorePropertiesFile = rootProject.file('key.properties')
to
def keystorePropertiesFile = rootProject.file('app/key.properties')
Upvotes: 2
Reputation: 951
Yeah, for me... I forgot to change my signingConfig
to singingConfigs.release
in my build.gradle
file.
buildTypes {
release {
//CHANGE THIS TO RELEASE
signingConfig signingConfigs.debug
}
}
Upvotes: 1
Reputation: 2136
On Windows you have to use 2 backslashes to indicate the path separation.
In your key.properties
, you should have something like this:
storeFile=D:\\flutterapps\\testapp\\key.jks
You don't need to copy your key.jks
file to your flutter project.
Upvotes: 55
Reputation: 1031
modified key.properties file with
storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=key.jks
instead of this
storePassword=123456
keyPassword=123456
keyAlias=key
storeFile=D:\flutterapps\testapp\key.jks
and also moved key.jks to D:\flutterapps\testapp\android\app\key.jks
as this path shown in error inside terminal
Thanks all.
Upvotes: 43
Reputation: 3222
it's wherever call it from in your build.gradle
. insert this:
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
and call this in above your android{}:
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
and that key.properties file (which should be in your root android folder) should have this:
storePassword=12345
keyPassword=12345
keyAlias=key
storeFile=/Users/me/somekey.jks
Upvotes: 5