React Native Generating Signed APK "KeyStore file not set for signing config release"

Viewed 48200

I am trying to generate a signed APK. I have my password.keystore file located in \Dictionary\android\app and when i ran gradlew assembleRelease on cmd, the error:

Execution failed for task ':app:validateSigningRelease'.

Keystore file not set for signing config release

Where should I store my password.keystore file? Because when I commented off the if (project.hasProperty("password.keystore") { it seems to work but with the following error instead:

Unable to process incoming event 'ProgressComplete ' (ProgressCompleteEvent)

How should I write my if condition or where should I store the password.keystore file?

The source code is as follows:

signingConfigs {
  release {
    if (project.hasProperty("password.keystore")) {
      storeFile file("password.keystore")
      storePassword "password"
      keyAlias "username"
      keyPassword "password"
    }
  }
}
13 Answers

In my case, my project was on RN version 0.59 while I was using 0.60 RC documentation. So inside app/build.gradle

If version 0.59 :

if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {

If version 0.60 :

if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {

The difference is the change from RELEASE to UPLOAD

I have found a solution!

If you have followed React Native's official instructions, just like me, you add following to your gradle.properties

MYAPP_RELEASE_STORE_FILE=<your-app>.keystore
MYAPP_RELEASE_KEY_ALIAS=<keystore-alias>
MYAPP_RELEASE_STORE_PASSWORD=<password>
MYAPP_RELEASE_KEY_PASSWORD=<password>

And then comes the part that I totally misunderstood.

In the app/build.gradle-file, you are not supposed to replace the strings. If your gradle.properties is like the one I pasted over, your app/build.gradle should look like this:

signingConfigs {
    release {
        if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}

What I originally did was replacing the strings (i.e. 'MYAPP_RELEASE_STORE_FILE' with the path to my keystore-file), but you are not supposed to replace any of the variables at all. I guess you could see the connection between the strings we created in gradle.properties and the release-config we have made in app/build.gradle.

Remember to have your .keystore-file inside android/app as well.

I actually prefer to store these parameters outside the app repo using environment variables since it contains sensitive information like password, etc.

signingConfigs {
    release {
        if (System.env.MYAPP_RELEASE_STORE_FILE != null) {
            storeFile       file(System.env.MYAPP_RELEASE_STORE_FILE)
            storePassword   System.env.MYAPP_RELEASE_STORE_PASSWORD
            keyAlias        System.env.MYAPP_RELEASE_KEY_ALIAS
            keyPassword     System.env.MYAPP_RELEASE_KEY_PASSWORD
        }
    }
}

Once this is done, I can just load up a bash script which has the details like

# path to my keystore
export MYAPP_RELEASE_STORE_FILE=/path/to/key.file
# ...

This way the signing config is completely isolated from the repo. This prevents you from making accidental commits with your secrets.

Make sure alias name used in gradle.properties is same as the one used while creating keystore ( using keytool )

the gradle.properties file i placed in android/gradle.properties and it worked for me, looks like in latest react .gradle/gradle.properties file if we place it in this location it does not pick from their.

After exploring all answers regarding this issue, none of the answer helped!

So tried below experiment and it helped!!!!

Place the my-release-key.keystore file under the android directory in your project folder.

Use ./gradlew bundleRelease than ./gradlew assembleRelease

Try to do like this :

           release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
            storeFile file('MYAPP_UPLOAD_STORE_FILE')
            storePassword 'MYAPP_UPLOAD_STORE_PASSWORD'
            keyAlias 'MYAPP_UPLOAD_KEY_ALIAS'
            keyPassword 'MYAPP_UPLOAD_KEY_PASSWORD'
        }
    }

In my case in my gradle.properties file was like

MYAPP_RELEASE_STORE_FILE=<your-app>.keystore
MYAPP_RELEASE_KEY_ALIAS=<keystore-alias>
MYAPP_RELEASE_STORE_PASSWORD=<password>
MYAPP_RELEASE_KEY_PASSWORD=<password>

and in my build.gradle file

release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }

I was using RELEASE in my gradle.properties instead of UPLOAD. Just changed the RELEASE to UPLOAD in gradle.properties and issue was gone.

Related