|
| 1 | +# flutter release guide |
| 2 | + |
| 3 | +## how to test your flutter app on a physical device ? |
| 4 | + |
| 5 | +* Connect your Android device to your computer with a USB cable. |
| 6 | +* Ensure that your have enabled USB DEBUGGING option |
| 7 | +* Navigate to <app dir> and run command |
| 8 | +``` |
| 9 | +flutter install |
| 10 | +``` |
| 11 | + |
| 12 | +## how to sign the apk or app bundle created using flutter ? |
| 13 | +To publish your app on Play Store, you need to give your app a digital signature |
| 14 | + |
| 15 | +### step 1 : Create a new keystore file ; if you have an existing keystore , skip this step |
| 16 | +* Run command in your terminal for linux/mac |
| 17 | +``` |
| 18 | +keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key |
| 19 | +``` |
| 20 | +* Fill in the required info inside the terminal |
| 21 | +``` |
| 22 | + Enter keystore password: test@12345 |
| 23 | + Re-enter new password: test@12345 |
| 24 | + |
| 25 | + What is your first and last name? |
| 26 | + [test]: test |
| 27 | + What is the name of your organizational unit? |
| 28 | + [test]: test |
| 29 | + What is the name of your organization? |
| 30 | + [test]: test |
| 31 | + What is the name of your City or Locality? |
| 32 | + [test]: test |
| 33 | + What is the name of your State or Province? |
| 34 | + [test]: test |
| 35 | + What is the two-letter country code for this unit? |
| 36 | + [tt]: tt |
| 37 | + Is CN=test, OU=test, O=test, L=test, ST=test, C=tt correct? |
| 38 | + [no]: yes |
| 39 | + |
| 40 | +//OUTPUT |
| 41 | + Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days |
| 42 | + for: CN=test, OU=test, O=test, L=test, ST=test, C=tt |
| 43 | + [Storing /home/<user name>/key.jks] |
| 44 | + |
| 45 | +``` |
| 46 | +* Keep the keystore file private; do not check it into public source control. |
| 47 | +* Always keep a backup of the keystore file |
| 48 | +* Common errors while signing the app |
| 49 | + * Command 'keytool' not found |
| 50 | + * run command |
| 51 | + ``` |
| 52 | + sudo apt install openjdk-11-jre-headless |
| 53 | + or |
| 54 | + sudo apt install openjdk-8-jre-headless |
| 55 | + ``` |
| 56 | + |
| 57 | +### step 2 : Reference the keystore from the app |
| 58 | +
|
| 59 | +* Create a file name key.properties in your android folder |
| 60 | +* Write the following lines inside the newly created file |
| 61 | +
|
| 62 | +``` |
| 63 | + storePassword=<password from previous step> |
| 64 | + keyPassword=<password from previous step> |
| 65 | + keyAlias=key |
| 66 | + storeFile=<location of the key store file, such as /Users/<user name>/key.jks> |
| 67 | +``` |
| 68 | +* Keep the key.properties file private; do not check it into public source control. |
| 69 | +* Always keep a backup of the key.properties file |
| 70 | +
|
| 71 | +### step 3 : Configure signing in gradle |
| 72 | +Navigate to <app dir>/android/app/build.gradle file. |
| 73 | +
|
| 74 | +1. Replace the following |
| 75 | +``` |
| 76 | +android { |
| 77 | +``` |
| 78 | +with |
| 79 | +``` |
| 80 | + def keystoreProperties = new Properties() |
| 81 | + def keystorePropertiesFile = rootProject.file('key.properties') |
| 82 | + if (keystorePropertiesFile.exists()) { |
| 83 | + keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) |
| 84 | + } |
| 85 | + |
| 86 | + android { |
| 87 | +``` |
| 88 | +
|
| 89 | +2. Replace the following |
| 90 | +``` |
| 91 | +buildTypes { |
| 92 | + release { |
| 93 | + // TODO: Add your own signing config for the release build. |
| 94 | + // Signing with the debug keys for now, |
| 95 | + // so `flutter run --release` works. |
| 96 | + signingConfig signingConfigs.debug |
| 97 | + } |
| 98 | + } |
| 99 | +``` |
| 100 | +with the signing config info |
| 101 | +``` |
| 102 | +signingConfigs { |
| 103 | + release { |
| 104 | + keyAlias keystoreProperties['keyAlias'] |
| 105 | + keyPassword keystoreProperties['keyPassword'] |
| 106 | + storeFile file(keystoreProperties['storeFile']) |
| 107 | + storePassword keystoreProperties['storePassword'] |
| 108 | + } |
| 109 | + } |
| 110 | + buildTypes { |
| 111 | + release { |
| 112 | + signingConfig signingConfigs.release |
| 113 | + } |
| 114 | + } |
| 115 | +``` |
| 116 | +
|
| 117 | +Now, every release build of your app will be signed automatically |
| 118 | +
|
| 119 | +## how to create APK file or Android App Bundle using flutter ? |
| 120 | +
|
| 121 | +### how to build an android app bundle (aab) using flutter ? |
| 122 | +Run command : Running flutter build defaults to a release build |
| 123 | +``` |
| 124 | +flutter build appbundle |
| 125 | +``` |
| 126 | +Note : release bundle for your app is created at <app dir>/build/app/outputs/bundle/release/app.aab |
| 127 | +
|
| 128 | +### how to build apk file using flutter ? |
| 129 | +* flutter build command defaults to a release build |
| 130 | +``` |
| 131 | +flutter build apk |
| 132 | +Note : this command builds a fat apk |
| 133 | +``` |
| 134 | +
|
| 135 | +OR |
| 136 | +
|
| 137 | +``` |
| 138 | +flutter build apk --split-per-abi |
| 139 | +``` |
| 140 | +Note : the above command generated two apk files |
| 141 | + * armeabi-v7a (32-bit) apk |
| 142 | + * arm64-v8a (64-bit) apk |
| 143 | + |
| 144 | +### What is a fat apk ? |
| 145 | +[Refer official docs](https://flutter.dev/docs/deployment/android#what-is-a-fat-apk) |
| 146 | +
|
| 147 | +## Useful Resources |
| 148 | +[Publish smaller apps with the Android App Bundle](https://www.youtube.com/watch?v=9D63S4ZRBls) |
| 149 | +
|
0 commit comments