25

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>
Gudguy
  • 923
  • 2
  • 9
  • 16
  • Which steps are you referring to from the official site? What is your directory structure? – Iain Duncan Dec 29 '18 at 21:15
  • It seems that it’s serching the .jks file inside the app folder and not the parent. Tey put it on ./android/app. Btw how did you set up the signin keystore? With AS, by hand in gradle file, or what? – shadowsheep Dec 29 '18 at 21:17
  • I set signing by this keytool -genkey -v -keystore D:\flutterapps\testapp\key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key in terminal and it gave succsesful mesaage and created key.jks file also in that path – Gudguy Dec 29 '18 at 21:25
  • It considering its path as key.properties file path instead key.jks – Gudguy Dec 29 '18 at 21:33

7 Answers7

53

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.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
Nathan Teyou
  • 2,116
  • 16
  • 14
39

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.

Gudguy
  • 923
  • 2
  • 9
  • 16
  • saved my day. Thank you. – Akram Chauhan May 13 '19 at 12:39
  • 4
    It's not the cause of the problem. The real cause is in windows's backslashes. The keytool thinks those are escape characters and just ignores them. You could whether do this D:\\flutterapps\\testapp\\key.jks or this D:/flutterapps/testapp/key.jks to avoid the problem. – Konstantin Nov 22 '19 at 11:17
  • 7
    If you are moving your key inside your app (not recommended), don't forget to add a line `key.jks` to your .gitignore file because this file should not be uploaded to any public repository. Also you need \\ instead of \ as mentioned above. – Md Azharuddin Jul 21 '20 at 09:32
  • 1
    With a second backslash per directory is enough. You don't need to move any key file. – Néstor Aug 24 '21 at 14:36
  • To emphasize the points above: MOVING YOUR .JKS INTO YOUR ANDROID DIRECTORY IS MERELY A *"WORKAROUND"*! It is *NOT* "best practice"! The real problem was the backslashes. You have two choices; either will work: A) `D:\\flutterapps\\testapp\\key.jks` or B) `D:/flutterapps/testapp/key.jks` – paulsm4 Nov 27 '21 at 18:45
5

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
blaneyneil
  • 3,122
  • 13
  • 14
  • Sorry I did mentioned that I already followed those three steps as per https://flutter.io/docs/deployment/android – Gudguy Dec 29 '18 at 21:18
  • 1
    it giving this weird error path Keystore file 'D:\flutterapps\publish\android\app\D: lutterappspublishkey.jks' not found for signing config 'release'. – Gudguy Dec 29 '18 at 21:20
  • what did you set as the storeFile? – blaneyneil Dec 29 '18 at 21:24
  • my key store file name is key.jks but it taking something as Keystore file 'D:\flutterapps\testapp\android\app\ (less than sign) D: lutterappspublishkey.jks (greater than sign)' not found for signing config 'release'. – Gudguy Dec 29 '18 at 21:29
  • you sure you're calling in the key.properties file? – blaneyneil Dec 29 '18 at 21:41
1

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
        }
    }
Mr. Arbitrary
  • 932
  • 11
  • 25
1

In build.gradle

Replace

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

to

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

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

Pythogen
  • 591
  • 5
  • 25
0

I experienced the same issue with my Flutter app and here's how I solved it on my Mac.

  1. Ensure that your key.properties file is located inside the android directory, so the path should be android/key.properties.

  2. 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
    
  3. 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.

  1. 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
    
  2. 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.

  1. Run flutter clean && flutter pub get
  2. Run 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.
Sharon Atim
  • 1,777
  • 16
  • 12