Changing upload key for Android React-Native Application
Asked Answered
T

1

8

We had to reset our Android Upload key for a React-Native Android Application. We contacted Google to reset the key.

Google asked us to complete the following steps: Here’s how to generate and register a new upload key:

Follow the instructions in the Android Studio Help Center to generate a new key. It must be different from any previous keys. Alternatively, you can use the following command line to generate a new key:

keytool -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks

This key must be a 2048 bit RSA key and have 25-year validity. Export the certificate for that key to PEM format:

keytool -export -rfc -alias upload -file upload_certificate.pem -keystore keystore.jks 

Reply to this email and attach the upload_certificate.pem file.

Further Steps
We now have the generated files, keystore.jks and an upload_certificate.pem file.

Previously our application used a '***-release-key.keystore' file to upload.

Build Process
gradle.properties file

MYAPP_RELEASE_STORE_FILE=APPNAME-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=APPNAMEapprelease

build.gradle file

def getPassword(String currentUser, String keyChain) {
  def stdout = new ByteArrayOutputStream()
  def stderr = new ByteArrayOutputStream()
  exec {
      commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w'
      standardOutput = stdout
      errorOutput = stderr
      ignoreExitValue true
  }
  //noinspection GroovyAssignabilityCheck
  stdout.toString().trim()
}

def releasekeypass = getPassword("APPNAME","android_keystore")
def releasekeyalias = getPassword("APPNAME","android_keystore")

Notes
We use fastlane to deploy the application. How do we get/change the .keystore file with the new files we have?

Trost answered 29/6, 2020 at 21:59 Comment(0)
D
3

The documentation casually tends to refer to .jks files as .keystore in some places. They are the same format.

Check for yourself:

file APPNAME-release-key.keystore
APPNAME-release-key.keystore : Java KeyStore 
> file keystore.jks
keystore.jks : Java KeyStore 

Then your solution is simple to rename keystore.jks to APPNAME-release-key.keystore.

Deannadeanne answered 7/7, 2020 at 0:34 Comment(4)
Thanks @fabio, Unfortunately, this still doesn't work. I've tried replacing the releasekeypass and releasekeyalias values with the password in a hardcoded string and it still complains. ``` No key with alias '-upload' found in keystore```Trost
Can you provide link to the instructions you cite? Here's how I generate keys: keytool -genkey -v -keystore keystore.jks -alias alias_name -keyalg RSA -keysize 2048 -validity 10000. And here's how to check for alias: keytool -list -v -keystore keystore.jksDeannadeanne
hold on, your error message states that your alias should be -upload when your command line creates upload. If it's a bug in React Native pls try generating jks with keytool -genkeypair -alias '-upload' -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jksDeannadeanne
is this the correct answer i.e. just changing the filename of the jks to a keystore one? Is that all u need to do ?Dexter

© 2022 - 2024 — McMap. All rights reserved.