|
| 1 | +--- |
| 2 | +name: distributing-tauri-for-android |
| 3 | +description: Guides the user through distributing Tauri applications for Android, including Google Play Store submission, APK and AAB generation, build configuration, signing setup, and version management. |
| 4 | +--- |
| 5 | + |
| 6 | +# Distributing Tauri Apps for Android |
| 7 | + |
| 8 | +This skill covers the complete workflow for preparing and distributing Tauri v2 applications on Android, including Google Play Store publication. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +Before distributing your Tauri app for Android: |
| 13 | + |
| 14 | +1. **Play Console Account**: Create a developer account at https://play.google.com/console/developers |
| 15 | +2. **Android SDK**: Ensure Android SDK is installed and configured |
| 16 | +3. **Code Signing**: Set up Android code signing (keystore) |
| 17 | +4. **Tauri Android Initialized**: Run `tauri android init` if not already done |
| 18 | + |
| 19 | +## App Icon Configuration |
| 20 | + |
| 21 | +After initializing Android support, configure your app icon: |
| 22 | + |
| 23 | +```bash |
| 24 | +# npm |
| 25 | +npm run tauri icon /path/to/app-icon.png |
| 26 | + |
| 27 | +# yarn |
| 28 | +yarn tauri icon /path/to/app-icon.png |
| 29 | + |
| 30 | +# pnpm |
| 31 | +pnpm tauri icon /path/to/app-icon.png |
| 32 | + |
| 33 | +# cargo |
| 34 | +cargo tauri icon /path/to/app-icon.png |
| 35 | +``` |
| 36 | + |
| 37 | +This generates icons in all required sizes for Android. |
| 38 | + |
| 39 | +## Build Configuration |
| 40 | + |
| 41 | +### tauri.conf.json Android Settings |
| 42 | + |
| 43 | +Configure Android-specific settings in your `tauri.conf.json`: |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "bundle": { |
| 48 | + "android": { |
| 49 | + "minSdkVersion": 24, |
| 50 | + "versionCode": 1 |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### Configuration Options |
| 57 | + |
| 58 | +| Option | Default | Description | |
| 59 | +|--------|---------|-------------| |
| 60 | +| `minSdkVersion` | 24 | Minimum Android SDK version (Android 7.0) | |
| 61 | +| `versionCode` | Auto-calculated | Integer version code for Play Store | |
| 62 | + |
| 63 | +### Version Code Calculation |
| 64 | + |
| 65 | +Tauri automatically calculates the version code from your app version: |
| 66 | + |
| 67 | +``` |
| 68 | +versionCode = major * 1000000 + minor * 1000 + patch |
| 69 | +``` |
| 70 | + |
| 71 | +**Example**: Version `1.2.3` becomes version code `1002003` |
| 72 | + |
| 73 | +Override this in `tauri.conf.json` if you need sequential numbering: |
| 74 | + |
| 75 | +```json |
| 76 | +{ |
| 77 | + "bundle": { |
| 78 | + "android": { |
| 79 | + "versionCode": 42 |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +### Minimum SDK Version |
| 86 | + |
| 87 | +Default minimum is Android 7.0 (SDK 24). For higher requirements: |
| 88 | + |
| 89 | +```json |
| 90 | +{ |
| 91 | + "bundle": { |
| 92 | + "android": { |
| 93 | + "minSdkVersion": 28 |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +**Common SDK versions**: |
| 100 | +- SDK 24: Android 7.0 (Nougat) |
| 101 | +- SDK 26: Android 8.0 (Oreo) |
| 102 | +- SDK 28: Android 9.0 (Pie) |
| 103 | +- SDK 29: Android 10 |
| 104 | +- SDK 30: Android 11 |
| 105 | +- SDK 31: Android 12 |
| 106 | +- SDK 33: Android 13 |
| 107 | +- SDK 34: Android 14 |
| 108 | + |
| 109 | +## Building for Distribution |
| 110 | + |
| 111 | +### Android App Bundle (AAB) - Recommended |
| 112 | + |
| 113 | +Google Play requires AAB format for new apps. Generate an AAB: |
| 114 | + |
| 115 | +```bash |
| 116 | +# npm |
| 117 | +npm run tauri android build -- --aab |
| 118 | + |
| 119 | +# yarn |
| 120 | +yarn tauri android build --aab |
| 121 | + |
| 122 | +# pnpm |
| 123 | +pnpm tauri android build -- --aab |
| 124 | + |
| 125 | +# cargo |
| 126 | +cargo tauri android build --aab |
| 127 | +``` |
| 128 | + |
| 129 | +**Output location**: |
| 130 | +``` |
| 131 | +gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab |
| 132 | +``` |
| 133 | + |
| 134 | +### APK Generation |
| 135 | + |
| 136 | +For testing or alternative distribution channels: |
| 137 | + |
| 138 | +```bash |
| 139 | +# npm |
| 140 | +npm run tauri android build -- --apk |
| 141 | + |
| 142 | +# yarn |
| 143 | +yarn tauri android build --apk |
| 144 | + |
| 145 | +# pnpm |
| 146 | +pnpm tauri android build -- --apk |
| 147 | + |
| 148 | +# cargo |
| 149 | +cargo tauri android build --apk |
| 150 | +``` |
| 151 | + |
| 152 | +### Architecture-Specific Builds |
| 153 | + |
| 154 | +Build for specific CPU architectures: |
| 155 | + |
| 156 | +```bash |
| 157 | +# Single architecture |
| 158 | +npm run tauri android build -- --target aarch64 |
| 159 | + |
| 160 | +# Multiple architectures |
| 161 | +npm run tauri android build -- --target aarch64 --target armv7 |
| 162 | +``` |
| 163 | + |
| 164 | +**Available targets**: |
| 165 | +- `aarch64` - ARM 64-bit (most modern devices) |
| 166 | +- `armv7` - ARM 32-bit (older devices) |
| 167 | +- `i686` - Intel 32-bit (emulators) |
| 168 | +- `x86_64` - Intel 64-bit (emulators, some Chromebooks) |
| 169 | + |
| 170 | +### Split APKs by Architecture |
| 171 | + |
| 172 | +Create separate APKs per architecture (useful for testing): |
| 173 | + |
| 174 | +```bash |
| 175 | +npm run tauri android build -- --apk --split-per-abi |
| 176 | +``` |
| 177 | + |
| 178 | +**Note**: Not needed for Play Store submission. Google Play automatically serves the correct architecture from your AAB. |
| 179 | + |
| 180 | +## Code Signing |
| 181 | + |
| 182 | +### Generate a Keystore |
| 183 | + |
| 184 | +Create a release keystore for signing: |
| 185 | + |
| 186 | +```bash |
| 187 | +keytool -genkey -v -keystore release-key.keystore \ |
| 188 | + -alias my-app-alias \ |
| 189 | + -keyalg RSA \ |
| 190 | + -keysize 2048 \ |
| 191 | + -validity 10000 |
| 192 | +``` |
| 193 | + |
| 194 | +**Important**: Store your keystore securely. Losing it means you cannot update your app. |
| 195 | + |
| 196 | +### Configure Signing in Gradle |
| 197 | + |
| 198 | +Create or update `gen/android/keystore.properties`: |
| 199 | + |
| 200 | +```properties |
| 201 | +storePassword=your_store_password |
| 202 | +keyPassword=your_key_password |
| 203 | +keyAlias=my-app-alias |
| 204 | +storeFile=/path/to/release-key.keystore |
| 205 | +``` |
| 206 | + |
| 207 | +Update `gen/android/app/build.gradle.kts` to use the keystore: |
| 208 | + |
| 209 | +```kotlin |
| 210 | +import java.util.Properties |
| 211 | +import java.io.FileInputStream |
| 212 | + |
| 213 | +val keystorePropertiesFile = rootProject.file("keystore.properties") |
| 214 | +val keystoreProperties = Properties() |
| 215 | +if (keystorePropertiesFile.exists()) { |
| 216 | + keystoreProperties.load(FileInputStream(keystorePropertiesFile)) |
| 217 | +} |
| 218 | + |
| 219 | +android { |
| 220 | + signingConfigs { |
| 221 | + create("release") { |
| 222 | + keyAlias = keystoreProperties["keyAlias"] as String |
| 223 | + keyPassword = keystoreProperties["keyPassword"] as String |
| 224 | + storeFile = file(keystoreProperties["storeFile"] as String) |
| 225 | + storePassword = keystoreProperties["storePassword"] as String |
| 226 | + } |
| 227 | + } |
| 228 | + buildTypes { |
| 229 | + release { |
| 230 | + signingConfig = signingConfigs.getByName("release") |
| 231 | + } |
| 232 | + } |
| 233 | +} |
| 234 | +``` |
| 235 | + |
| 236 | +### Environment Variables for CI/CD |
| 237 | + |
| 238 | +For automated builds, use environment variables: |
| 239 | + |
| 240 | +```kotlin |
| 241 | +android { |
| 242 | + signingConfigs { |
| 243 | + create("release") { |
| 244 | + keyAlias = System.getenv("ANDROID_KEY_ALIAS") |
| 245 | + keyPassword = System.getenv("ANDROID_KEY_PASSWORD") |
| 246 | + storeFile = file(System.getenv("ANDROID_KEYSTORE_PATH")) |
| 247 | + storePassword = System.getenv("ANDROID_STORE_PASSWORD") |
| 248 | + } |
| 249 | + } |
| 250 | +} |
| 251 | +``` |
| 252 | + |
| 253 | +## Google Play Store Submission |
| 254 | + |
| 255 | +### Pre-Submission Checklist |
| 256 | + |
| 257 | +1. **App signed** with release keystore |
| 258 | +2. **Version code** incremented from previous release |
| 259 | +3. **App icon** configured in all required sizes |
| 260 | +4. **Screenshots** prepared (required by Play Store) |
| 261 | +5. **Privacy policy** URL ready (required for most apps) |
| 262 | +6. **Content rating** questionnaire completed |
| 263 | + |
| 264 | +### Upload Process |
| 265 | + |
| 266 | +1. **Navigate** to Play Console: https://play.google.com/console/developers |
| 267 | +2. **Create application** or select existing app |
| 268 | +3. **Upload AAB** file from: |
| 269 | + ``` |
| 270 | + gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab |
| 271 | + ``` |
| 272 | +4. **Complete store listing** (title, description, screenshots) |
| 273 | +5. **Set content rating** |
| 274 | +6. **Configure pricing and distribution** |
| 275 | +7. **Submit for review** |
| 276 | + |
| 277 | +### First Release Requirements |
| 278 | + |
| 279 | +The initial submission requires manual upload through Play Console for signature verification. Google will manage your app signing key through Play App Signing. |
| 280 | + |
| 281 | +### Automation Note |
| 282 | + |
| 283 | +Tauri currently does not offer built-in automation for creating Android releases. However, you can use the Google Play Developer API for automated submissions in CI/CD pipelines. |
| 284 | + |
| 285 | +## Troubleshooting |
| 286 | + |
| 287 | +### Build Fails with Signing Error |
| 288 | + |
| 289 | +Ensure your keystore path is absolute or relative to the correct directory: |
| 290 | + |
| 291 | +```properties |
| 292 | +# Absolute path |
| 293 | +storeFile=/Users/username/keys/release-key.keystore |
| 294 | + |
| 295 | +# Relative to gen/android directory |
| 296 | +storeFile=../../release-key.keystore |
| 297 | +``` |
| 298 | + |
| 299 | +### Version Code Not Incrementing |
| 300 | + |
| 301 | +If using auto-calculation, ensure your `package.json` or `Cargo.toml` version is updated. For manual control: |
| 302 | + |
| 303 | +```json |
| 304 | +{ |
| 305 | + "bundle": { |
| 306 | + "android": { |
| 307 | + "versionCode": 2 |
| 308 | + } |
| 309 | + } |
| 310 | +} |
| 311 | +``` |
| 312 | + |
| 313 | +### APK Not Installing on Device |
| 314 | + |
| 315 | +Check minimum SDK version compatibility: |
| 316 | + |
| 317 | +```bash |
| 318 | +# Check device Android version |
| 319 | +adb shell getprop ro.build.version.sdk |
| 320 | +``` |
| 321 | + |
| 322 | +### AAB Too Large |
| 323 | + |
| 324 | +Consider using `--split-per-abi` for testing, but for Play Store, Google handles this automatically. If still too large: |
| 325 | + |
| 326 | +1. Optimize your frontend assets |
| 327 | +2. Use dynamic feature modules |
| 328 | +3. Enable ProGuard/R8 minification |
| 329 | + |
| 330 | +## Quick Reference |
| 331 | + |
| 332 | +### Common Build Commands |
| 333 | + |
| 334 | +```bash |
| 335 | +# Development build |
| 336 | +npm run tauri android dev |
| 337 | + |
| 338 | +# Release AAB for Play Store |
| 339 | +npm run tauri android build -- --aab |
| 340 | + |
| 341 | +# Release APK for testing |
| 342 | +npm run tauri android build -- --apk |
| 343 | + |
| 344 | +# Specific architecture |
| 345 | +npm run tauri android build -- --aab --target aarch64 |
| 346 | +``` |
| 347 | + |
| 348 | +### File Locations |
| 349 | + |
| 350 | +| File | Location | |
| 351 | +|------|----------| |
| 352 | +| AAB output | `gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab` | |
| 353 | +| APK output | `gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk` | |
| 354 | +| Gradle config | `gen/android/app/build.gradle.kts` | |
| 355 | +| Keystore properties | `gen/android/keystore.properties` | |
| 356 | +| Android manifest | `gen/android/app/src/main/AndroidManifest.xml` | |
| 357 | + |
| 358 | +### Resources |
| 359 | + |
| 360 | +- [Google Play Console](https://play.google.com/console/developers) |
| 361 | +- [Tauri Android Documentation](https://v2.tauri.app/distribute/google-play) |
| 362 | +- [Google Play Release Checklist](https://developer.android.com/distribute/best-practices/launch/launch-checklist) |
| 363 | +- [Play App Signing](https://developer.android.com/studio/publish/app-signing) |
0 commit comments