title: Changing upload key for Android React-Native Application
body: <p>We had to reset our Android Upload key for a React-Native Android Application. We contacted Google to reset the key.</p>
  <p>Google asked us to complete the following steps:
  Here’s how to generate and register a new upload key:</p>
  <p>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:</p>
  <pre><code>keytool -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks
  </code></pre>
  <p>This key must be a 2048 bit RSA key and have 25-year validity.
  Export the certificate for that key to PEM format:</p>
  <pre><code>keytool -export -rfc -alias upload -file upload_certificate.pem -keystore keystore.jks 
  </code></pre>
  <p>Reply to this email and attach the upload_certificate.pem file.</p>
  <p><strong>Further Steps</strong><br />
  We now have the generated files, <code>keystore.jks</code> and an <code>upload_certificate.pem</code> file.</p>
  <p>Previously our application used a '***-release-key.keystore' file to upload.</p>
  <p><strong>Build Process</strong><br />
  gradle.properties file</p>
  <pre><code>MYAPP_RELEASE_STORE_FILE=APPNAME-release-key.keystore
  MYAPP_RELEASE_KEY_ALIAS=APPNAMEapprelease
  </code></pre>
  <p>build.gradle file</p>
  <pre><code>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(&quot;APPNAME&quot;,&quot;android_keystore&quot;)
  def releasekeyalias = getPassword(&quot;APPNAME&quot;,&quot;android_keystore&quot;)
  </code></pre>
  <p><strong>Notes</strong><br />
  We use fastlane to deploy the application. How do we get/change the .keystore file with the new files we have?</p>