Skip to content

Instantly share code, notes, and snippets.

@moazmohamed20
Created April 28, 2024 15:50
Show Gist options
  • Save moazmohamed20/a5bd24d3dc4332fca998a854de2a0398 to your computer and use it in GitHub Desktop.
Save moazmohamed20/a5bd24d3dc4332fca998a854de2a0398 to your computer and use it in GitHub Desktop.

Deploy to Play Store

1. Create /android/key.properties

keyAlias=upload
keyPassword=####
storePassword=####
storeFile=../app/upload-keystore.jks

2. Generate /android/app/upload-keystore.jks

Using Terminal

keytool -genkey -v -keystore ./android/app/upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

Note

  • If keytool Not Found, Install Java JDK.
  • Use The Same Password Used in key.properties: ####
  • The -storetype JKS tag is only required for Java 9 or newer. As of the Java 9 release, the keystore type defaults to PKS12.

Tip

To Convert From JKS → PKCS12

keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.jks -deststoretype pkcs12

To Convert From PKCS12 → JKS

keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.jks -deststoretype jks

Using Android Studio Tools

  1. In the menu bar, click Build > Generate Signed Bundle/APK.
  2. In the Generate Signed Bundle or APK dialog, select Android App Bundle or APK and click Next.
  3. Below the field for Key store path, click Create new.
  4. On the New Key Store window, provide the following information for your keystore and key, as shown in figure.

Android Studio Tool Example

For More Details Check This Out.

3. Configure /android/app/build.gradle

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
  ...

  signingConfigs {
      release {
          keyAlias keystoreProperties['keyAlias']
          keyPassword keystoreProperties['keyPassword']
          storePassword keystoreProperties['storePassword']
          storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
      }
  }
  buildTypes {
      release {
        // TODO: Add your own signing config for the release build.
        // Signing with the debug keys for now, so `flutter run --release` works.
        // signingConfig signingConfigs.debug
        signingConfig signingConfigs.release
      }
  }

}

Note

You might need to run flutter clean after changing the gradle file. This prevents cached builds from affecting the signing process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment