distributing-tauri-for-android

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Distributing Tauri Apps for Android

Tauri应用的Android平台分发指南

This skill covers the complete workflow for preparing and distributing Tauri v2 applications on Android, including Google Play Store publication.
本技能涵盖了Tauri v2应用在Android平台上的准备与分发完整工作流,包括Google Play商店发布流程。

Prerequisites

前置条件

Before distributing your Tauri app for Android:
  1. Play Console Account: Create a developer account at https://play.google.com/console/developers
  2. Android SDK: Ensure Android SDK is installed and configured
  3. Code Signing: Set up Android code signing (keystore)
  4. Tauri Android Initialized: Run
    tauri android init
    if not already done
在分发你的Tauri Android应用之前:
  1. Play Console账号:在https://play.google.com/console/developers 创建开发者账号
  2. Android SDK:确保Android SDK已安装并配置完成
  3. 代码签名:设置Android代码签名(密钥库)
  4. 初始化Tauri Android支持:如果尚未完成,运行
    tauri android init

App Icon Configuration

应用图标配置

After initializing Android support, configure your app icon:
bash
undefined
初始化Android支持后,配置你的应用图标:
bash
undefined

npm

npm

npm run tauri icon /path/to/app-icon.png
npm run tauri icon /path/to/app-icon.png

yarn

yarn

yarn tauri icon /path/to/app-icon.png
yarn tauri icon /path/to/app-icon.png

pnpm

pnpm

pnpm tauri icon /path/to/app-icon.png
pnpm tauri icon /path/to/app-icon.png

cargo

cargo

cargo tauri icon /path/to/app-icon.png

This generates icons in all required sizes for Android.
cargo tauri icon /path/to/app-icon.png

此命令会生成Android所需的所有尺寸图标。

Build Configuration

构建配置

tauri.conf.json Android Settings

tauri.conf.json中的Android设置

Configure Android-specific settings in your
tauri.conf.json
:
json
{
  "bundle": {
    "android": {
      "minSdkVersion": 24,
      "versionCode": 1
    }
  }
}
tauri.conf.json
中配置Android相关设置:
json
{
  "bundle": {
    "android": {
      "minSdkVersion": 24,
      "versionCode": 1
    }
  }
}

Configuration Options

配置选项

OptionDefaultDescription
minSdkVersion
24Minimum Android SDK version (Android 7.0)
versionCode
Auto-calculatedInteger version code for Play Store
选项默认值描述
minSdkVersion
24最低Android SDK版本(Android 7.0)
versionCode
自动计算用于Play Store的整数版本代码

Version Code Calculation

版本代码计算

Tauri automatically calculates the version code from your app version:
versionCode = major * 1000000 + minor * 1000 + patch
Example: Version
1.2.3
becomes version code
1002003
Override this in
tauri.conf.json
if you need sequential numbering:
json
{
  "bundle": {
    "android": {
      "versionCode": 42
    }
  }
}
Tauri会根据你的应用版本自动计算版本代码:
versionCode = major * 1000000 + minor * 1000 + patch
示例:版本
1.2.3
对应的版本代码为
1002003
如果需要连续编号,可以在
tauri.conf.json
中手动覆盖:
json
{
  "bundle": {
    "android": {
      "versionCode": 42
    }
  }
}

Minimum SDK Version

最低SDK版本

Default minimum is Android 7.0 (SDK 24). For higher requirements:
json
{
  "bundle": {
    "android": {
      "minSdkVersion": 28
    }
  }
}
Common SDK versions:
  • SDK 24: Android 7.0 (Nougat)
  • SDK 26: Android 8.0 (Oreo)
  • SDK 28: Android 9.0 (Pie)
  • SDK 29: Android 10
  • SDK 30: Android 11
  • SDK 31: Android 12
  • SDK 33: Android 13
  • SDK 34: Android 14
默认最低版本为Android 7.0(SDK 24)。如果需要更高版本:
json
{
  "bundle": {
    "android": {
      "minSdkVersion": 28
    }
  }
}
常见SDK版本:
  • SDK 24: Android 7.0(Nougat)
  • SDK 26: Android 8.0(Oreo)
  • SDK 28: Android 9.0(Pie)
  • SDK 29: Android 10
  • SDK 30: Android 11
  • SDK 31: Android 12
  • SDK 33: Android 13
  • SDK 34: Android 14

Building for Distribution

分发构建

Android App Bundle (AAB) - Recommended

Android App Bundle (AAB) - 推荐格式

Google Play requires AAB format for new apps. Generate an AAB:
bash
undefined
Google Play要求新应用使用AAB格式。生成AAB:
bash
undefined

npm

npm

npm run tauri android build -- --aab
npm run tauri android build -- --aab

yarn

yarn

yarn tauri android build --aab
yarn tauri android build --aab

pnpm

pnpm

pnpm tauri android build -- --aab
pnpm tauri android build -- --aab

cargo

cargo

cargo tauri android build --aab

**Output location**:
gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab
undefined
cargo tauri android build --aab

**输出位置**:
gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab
undefined

APK Generation

APK生成

For testing or alternative distribution channels:
bash
undefined
用于测试或其他分发渠道:
bash
undefined

npm

npm

npm run tauri android build -- --apk
npm run tauri android build -- --apk

yarn

yarn

yarn tauri android build --apk
yarn tauri android build --apk

pnpm

pnpm

pnpm tauri android build -- --apk
pnpm tauri android build -- --apk

cargo

cargo

cargo tauri android build --apk
undefined
cargo tauri android build --apk
undefined

Architecture-Specific Builds

特定架构构建

Build for specific CPU architectures:
bash
undefined
针对特定CPU架构构建:
bash
undefined

Single architecture

单一架构

npm run tauri android build -- --target aarch64
npm run tauri android build -- --target aarch64

Multiple architectures

多架构

npm run tauri android build -- --target aarch64 --target armv7

**Available targets**:
- `aarch64` - ARM 64-bit (most modern devices)
- `armv7` - ARM 32-bit (older devices)
- `i686` - Intel 32-bit (emulators)
- `x86_64` - Intel 64-bit (emulators, some Chromebooks)
npm run tauri android build -- --target aarch64 --target armv7

**可用目标架构**:
- `aarch64` - ARM 64位(多数现代设备)
- `armv7` - ARM 32位(旧设备)
- `i686` - Intel 32位(模拟器)
- `x86_64` - Intel 64位(模拟器、部分Chromebook)

Split APKs by Architecture

按架构拆分APK

Create separate APKs per architecture (useful for testing):
bash
npm run tauri android build -- --apk --split-per-abi
Note: Not needed for Play Store submission. Google Play automatically serves the correct architecture from your AAB.
为每个架构创建独立APK(适用于测试):
bash
npm run tauri android build -- --apk --split-per-abi
注意:Play Store提交不需要此操作。Google Play会自动从你的AAB中为设备提供对应架构的版本。

Code Signing

代码签名

Generate a Keystore

生成密钥库

Create a release keystore for signing:
bash
keytool -genkey -v -keystore release-key.keystore \
  -alias my-app-alias \
  -keyalg RSA \
  -keysize 2048 \
  -validity 10000
Important: Store your keystore securely. Losing it means you cannot update your app.
创建用于签名的发布密钥库:
bash
keytool -genkey -v -keystore release-key.keystore \
  -alias my-app-alias \
  -keyalg RSA \
  -keysize 2048 \
  -validity 10000
重要提示:请安全存储你的密钥库。丢失密钥库将导致你无法更新应用。

Configure Signing in Gradle

在Gradle中配置签名

Create or update
gen/android/keystore.properties
:
properties
storePassword=your_store_password
keyPassword=your_key_password
keyAlias=my-app-alias
storeFile=/path/to/release-key.keystore
Update
gen/android/app/build.gradle.kts
to use the keystore:
kotlin
import java.util.Properties
import java.io.FileInputStream

val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}

android {
    signingConfigs {
        create("release") {
            keyAlias = keystoreProperties["keyAlias"] as String
            keyPassword = keystoreProperties["keyPassword"] as String
            storeFile = file(keystoreProperties["storeFile"] as String)
            storePassword = keystoreProperties["storePassword"] as String
        }
    }
    buildTypes {
        release {
            signingConfig = signingConfigs.getByName("release")
        }
    }
}
创建或更新
gen/android/keystore.properties
properties
storePassword=your_store_password
keyPassword=your_key_password
keyAlias=my-app-alias
storeFile=/path/to/release-key.keystore
更新
gen/android/app/build.gradle.kts
以使用该密钥库:
kotlin
import java.util.Properties
import java.io.FileInputStream

val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}

android {
    signingConfigs {
        create("release") {
            keyAlias = keystoreProperties["keyAlias"] as String
            keyPassword = keystoreProperties["keyPassword"] as String
            storeFile = file(keystoreProperties["storeFile"] as String)
            storePassword = keystoreProperties["storePassword"] as String
        }
    }
    buildTypes {
        release {
            signingConfig = signingConfigs.getByName("release")
        }
    }
}

Environment Variables for CI/CD

CI/CD环境变量

For automated builds, use environment variables:
kotlin
android {
    signingConfigs {
        create("release") {
            keyAlias = System.getenv("ANDROID_KEY_ALIAS")
            keyPassword = System.getenv("ANDROID_KEY_PASSWORD")
            storeFile = file(System.getenv("ANDROID_KEYSTORE_PATH"))
            storePassword = System.getenv("ANDROID_STORE_PASSWORD")
        }
    }
}
对于自动化构建,使用环境变量:
kotlin
android {
    signingConfigs {
        create("release") {
            keyAlias = System.getenv("ANDROID_KEY_ALIAS")
            keyPassword = System.getenv("ANDROID_KEY_PASSWORD")
            storeFile = file(System.getenv("ANDROID_KEYSTORE_PATH"))
            storePassword = System.getenv("ANDROID_STORE_PASSWORD")
        }
    }
}

Google Play Store Submission

Google Play商店提交

Pre-Submission Checklist

提交前检查清单

  1. App signed with release keystore
  2. Version code incremented from previous release
  3. App icon configured in all required sizes
  4. Screenshots prepared (required by Play Store)
  5. Privacy policy URL ready (required for most apps)
  6. Content rating questionnaire completed
  1. 应用已签名:使用发布密钥库签名
  2. 版本代码已递增:比上一版本更高
  3. 应用图标已配置:包含所有所需尺寸
  4. 截图已准备:Play Store要求提供
  5. 隐私政策URL已准备:多数应用需要
  6. 内容评级问卷已完成

Upload Process

上传流程

  1. Navigate to Play Console: https://play.google.com/console/developers
  2. Create application or select existing app
  3. Upload AAB file from:
    gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab
  4. Complete store listing (title, description, screenshots)
  5. Set content rating
  6. Configure pricing and distribution
  7. Submit for review
  1. 访问Play Console:https://play.google.com/console/developers
  2. 创建应用或选择现有应用
  3. 上传AAB文件,文件路径:
    gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab
  4. 完成商店列表(标题、描述、截图)
  5. 设置内容评级
  6. 配置定价与分发范围
  7. 提交审核

First Release Requirements

首次发布要求

The initial submission requires manual upload through Play Console for signature verification. Google will manage your app signing key through Play App Signing.
首次提交需要通过Play Console手动上传以进行签名验证。Google会通过Play应用签名管理你的应用签名密钥。

Automation Note

自动化说明

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.
Tauri目前不提供创建Android版本的内置自动化功能。不过你可以在CI/CD流水线中使用Google Play开发者API实现自动化提交。

Troubleshooting

故障排除

Build Fails with Signing Error

构建时出现签名错误

Ensure your keystore path is absolute or relative to the correct directory:
properties
undefined
确保密钥库路径为绝对路径或相对于正确目录:
properties
undefined

Absolute path

绝对路径

storeFile=/Users/username/keys/release-key.keystore
storeFile=/Users/username/keys/release-key.keystore

Relative to gen/android directory

相对于gen/android目录的相对路径

storeFile=../../release-key.keystore
undefined
storeFile=../../release-key.keystore
undefined

Version Code Not Incrementing

版本代码未递增

If using auto-calculation, ensure your
package.json
or
Cargo.toml
version is updated. For manual control:
json
{
  "bundle": {
    "android": {
      "versionCode": 2
    }
  }
}
如果使用自动计算,请确保
package.json
Cargo.toml
中的版本已更新。如需手动控制:
json
{
  "bundle": {
    "android": {
      "versionCode": 2
    }
  }
}

APK Not Installing on Device

APK无法在设备上安装

Check minimum SDK version compatibility:
bash
undefined
检查最低SDK版本兼容性:
bash
undefined

Check device Android version

检查设备Android版本

adb shell getprop ro.build.version.sdk
undefined
adb shell getprop ro.build.version.sdk
undefined

AAB Too Large

AAB文件过大

Consider using
--split-per-abi
for testing, but for Play Store, Google handles this automatically. If still too large:
  1. Optimize your frontend assets
  2. Use dynamic feature modules
  3. Enable ProGuard/R8 minification
测试时可以考虑使用
--split-per-abi
,但Play Store会自动处理此问题。如果仍然过大:
  1. 优化前端资源
  2. 使用动态功能模块
  3. 启用ProGuard/R8代码混淆

Quick Reference

快速参考

Common Build Commands

常用构建命令

bash
undefined
bash
undefined

Development build

开发构建

npm run tauri android dev
npm run tauri android dev

Release AAB for Play Store

用于Play Store的发布版AAB

npm run tauri android build -- --aab
npm run tauri android build -- --aab

Release APK for testing

用于测试的发布版APK

npm run tauri android build -- --apk
npm run tauri android build -- --apk

Specific architecture

特定架构构建

npm run tauri android build -- --aab --target aarch64
undefined
npm run tauri android build -- --aab --target aarch64
undefined

File Locations

文件位置

FileLocation
AAB output
gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab
APK output
gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk
Gradle config
gen/android/app/build.gradle.kts
Keystore properties
gen/android/keystore.properties
Android manifest
gen/android/app/src/main/AndroidManifest.xml
文件位置
AAB输出文件
gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab
APK输出文件
gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk
Gradle配置文件
gen/android/app/build.gradle.kts
密钥库属性文件
gen/android/keystore.properties
Android清单文件
gen/android/app/src/main/AndroidManifest.xml

Resources

参考资源