Search code examples
androidreact-nativecertificateapkkeystore

Generate signed apk for React Native Android application using existing certificate


I have an Android app certificate with a file type of FILE that was created back in 2012 for my Android app written in Java. Now I have updated that app using React Native.

How can I use the existing certificate to generate keystore and sign my updated app to be released on Google Play?

I've tried this even though the React Native certificate extension is .keystore

keytool -importcert -file "your.cer" -keystore your.jks -alias "<anything>"

and I got the following error

keytool error: java.lang.Exception: Input not an X.509 certificate

I expect to have a .keystore file that allows me to release an update of my existing Android app.


Solution

  • You don't need to create keystore file. you can use existing jks file to sign the app. Do as follow:

    • Put your jks file in the app directory
    • add the following code in your gradle.poperties file.

      MYAPP_RELEASE_STORE_FILE=filename.jks
      MYAPP_RELEASE_KEY_ALIAS=your-key-alias
      MYAPP_RELEASE_STORE_PASSWORD=your-store-password
      MYAPP_RELEASE_KEY_PASSWORD=your-release-key-password
      
    • Now add the signingConfigs in build.gradle file as below:

      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
              }
          }
      }
      
      buildTypes {
          release {
              signingConfig signingConfigs.release
          }
      }
      
    • Now you can sing your using your existing jks file.