React-native: “Keystore was tampered with, or password was incorrect” when attempting to generate signed apk

Created on 20 Jul 2016  Â·  9Comments  Â·  Source: facebook/react-native

Version 0.29.1
Android Only

I start off by running keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000 in my project directory.

Then I put my-release-key.keystore in my project's android/app directory.

Now, there isn't a ~/.gradle/gradle.properties directory like facebook says there is, but there is a gradle.properties in the android folder, so I set up my gradle variables and my gradle.properties ends up looking like this:

android.useDeprecatedNdk=true
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=password123
MYAPP_RELEASE_KEY_PASSWORD=password123

Next, I open up android/app/build.gradle and add my gradle variables and set it for release like this:

...
android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            storeFile file(MYAPP_RELEASE_STORE_FILE)
            storePassword MYAPP_RELEASE_STORE_PASSWORD
            keyAlias MYAPP_RELEASE_KEY_ALIAS
            keyPassword MYAPP_RELEASE_KEY_PASSWORD
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...

And then I finally run cd android && ./gradlew assembleRelease and get the error in the title saying that my Keystore was tampered with or my password is correct.

Because I've done this cycle so many times, I'm inclined to believe that I am somehow tampering with the keystore.

Locked

Most helpful comment

I have the same problem when ./gradlew assembleRelease, did create multiple keystores over and over again but still the message. 'Keystore was tampered with, or password was incorrect'.
The gradle.properties is located when building and is finding the correct keystore. I can list the entries of the keystore.

Version React Native: 0.46.1
OS: Win 10

keytool -genkey -v -keystore test.keystore -alias test -keyalg RSA -keysize 2048 -validity 10000

gradle.properties

MYAPP_RELEASE_STORE_FILE=test.keystore
MYAPP_RELEASE_KEY_ALIAS=test
MYAPP_RELEASE_STORE_PASSWORD=mypassword 
MYAPP_RELEASE_KEY_PASSWORD=mypassword
##\android\app>
Enter keystore password:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

test, Jul 10, 2017, PrivateKeyEntry,
Certificate fingerprint (SHA1): ##:##

Solution temporary was hard code the settings

```javascript
signingConfigs {
release {
//if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file("test.keystore")
storePassword "test"
keyAlias "test"
keyPassword "mypassword"
// }
}
````
After testing with java.lang.System.console(MYAPP_RELEASE_STORE_PASSWORD) it seems to be that there was a space after the password in the gradle.properties file.

javascript signingConfigs { release { if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) { java.lang.System.console(MYAPP_RELEASE_STORE_PASSWORD) } } }

All 9 comments

i have same problem。When i use AS build release apk,AS is ok。i try many time。

I am facing the same issue. Using Build -> Generate Signed APK in android studio works, but putting the config in build.gradle doesn't.

~/gradle/gradle.properties means
c:/Users/UserName/.gradle/gradle.properties (Windows)
That file isnt local to Ur project. Its available to all Ur projects which use gradle.

Works for me if I edit the above file instead of files in project.

Same steps as U. Only change being location of gradle.properties.

@IgorGanapolsky How? What directory do you have to be in to generate the APK with Android Studio?

@ashwin0003 Could you elaborate?

I'm going to close this issue since this is not an issue specific to React Native. Feel free to continue discussion here or move to StackOverflow.

~/ means Ur user home directory.

For windows 7/10 its C:UsersUserName
For Ubuntu its /home/UserName

Setting up gradle variables

Place the my-release-key.keystore file under the android/app directory in your project folder.
Edit the file ~/.gradle/gradle.properties and add the following (replace ***** with the correct keystore password, alias and key password),
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****
These are going to be global gradle variables, which we can later use in our gradle config to sign our app.


The first step is at Ur react native project folder.
The 2nd step is at the user home folder.

Note his explanation about global gradle variables. 1st step project folder. 2nd step global gradle installed folder.

Main point being ~/ means C:UsersUserName for windows and /home/UserName/ for Ubuntu.

Example.

My folders
Windows 10.

React project e:ReactAwesomeProject
Windows drive c:

Setting up gradle properties.
1) Placed keystore file at e:ReactAwesomeProjectandroidapp
2) Edited c:UsersAshwin.gradlegradle.properties

U messed up the 2nd step. U edited the wrong file. U eidted e:ReactAwesomeProjectandroidgradle.properties. Ur supposed to edit c:UsersAshwin.gradlegradle.properties

No probs with react-native. U didnt understand the meaning of ~/. That is a pretty basic thing to know.

I was trying to build based on a project-specific gradle.properties (i.e. at projectDir/android/gradle.properties), but a global gradle.properties I had configured during a previous project was being used instead. The fix for me was to delete my global gradle.properties (i.e Users/YourName/.gradle/gradle.properties)

I have the same problem when ./gradlew assembleRelease, did create multiple keystores over and over again but still the message. 'Keystore was tampered with, or password was incorrect'.
The gradle.properties is located when building and is finding the correct keystore. I can list the entries of the keystore.

Version React Native: 0.46.1
OS: Win 10

keytool -genkey -v -keystore test.keystore -alias test -keyalg RSA -keysize 2048 -validity 10000

gradle.properties

MYAPP_RELEASE_STORE_FILE=test.keystore
MYAPP_RELEASE_KEY_ALIAS=test
MYAPP_RELEASE_STORE_PASSWORD=mypassword 
MYAPP_RELEASE_KEY_PASSWORD=mypassword
##\android\app>
Enter keystore password:

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

test, Jul 10, 2017, PrivateKeyEntry,
Certificate fingerprint (SHA1): ##:##

Solution temporary was hard code the settings

```javascript
signingConfigs {
release {
//if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file("test.keystore")
storePassword "test"
keyAlias "test"
keyPassword "mypassword"
// }
}
````
After testing with java.lang.System.console(MYAPP_RELEASE_STORE_PASSWORD) it seems to be that there was a space after the password in the gradle.properties file.

javascript signingConfigs { release { if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) { java.lang.System.console(MYAPP_RELEASE_STORE_PASSWORD) } } }

After two years, I solved this by removing ~/gradle.properties or ~/.gradle/gradle.properties... one of those. Forgot which.

Completely forgot about posting this lol

looking at my bash history:
517 cd ~/.gradle
518 ls
519 open gradle.properties
520 rm gradle.properties

So it was rm ~/.gradle/gradle.properties

Was this page helpful?
0 / 5 - 0 ratings