distributing-tauri-for-android
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDistributing 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:
- Play Console Account: Create a developer account at https://play.google.com/console/developers
- Android SDK: Ensure Android SDK is installed and configured
- Code Signing: Set up Android code signing (keystore)
- Tauri Android Initialized: Run if not already done
tauri android init
在分发你的Tauri Android应用之前:
- Play Console账号:在https://play.google.com/console/developers 创建开发者账号
- Android SDK:确保Android SDK已安装并配置完成
- 代码签名:设置Android代码签名(密钥库)
- 初始化Tauri Android支持:如果尚未完成,运行
tauri android init
App Icon Configuration
应用图标配置
After initializing Android support, configure your app icon:
bash
undefined初始化Android支持后,配置你的应用图标:
bash
undefinednpm
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.jsonjson
{
"bundle": {
"android": {
"minSdkVersion": 24,
"versionCode": 1
}
}
}在中配置Android相关设置:
tauri.conf.jsonjson
{
"bundle": {
"android": {
"minSdkVersion": 24,
"versionCode": 1
}
}
}Configuration Options
配置选项
| Option | Default | Description |
|---|---|---|
| 24 | Minimum Android SDK version (Android 7.0) |
| Auto-calculated | Integer version code for Play Store |
| 选项 | 默认值 | 描述 |
|---|---|---|
| 24 | 最低Android SDK版本(Android 7.0) |
| 自动计算 | 用于Play Store的整数版本代码 |
Version Code Calculation
版本代码计算
Tauri automatically calculates the version code from your app version:
versionCode = major * 1000000 + minor * 1000 + patchExample: Version becomes version code
1.2.31002003Override this in if you need sequential numbering:
tauri.conf.jsonjson
{
"bundle": {
"android": {
"versionCode": 42
}
}
}Tauri会根据你的应用版本自动计算版本代码:
versionCode = major * 1000000 + minor * 1000 + patch示例:版本对应的版本代码为
1.2.31002003如果需要连续编号,可以在中手动覆盖:
tauri.conf.jsonjson
{
"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
undefinedGoogle Play要求新应用使用AAB格式。生成AAB:
bash
undefinednpm
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
undefinedcargo tauri android build --aab
**输出位置**:gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab
undefinedAPK Generation
APK生成
For testing or alternative distribution channels:
bash
undefined用于测试或其他分发渠道:
bash
undefinednpm
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
undefinedcargo tauri android build --apk
undefinedArchitecture-Specific Builds
特定架构构建
Build for specific CPU architectures:
bash
undefined针对特定CPU架构构建:
bash
undefinedSingle 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-abiNote: 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 10000Important: 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.propertiesproperties
storePassword=your_store_password
keyPassword=your_key_password
keyAlias=my-app-alias
storeFile=/path/to/release-key.keystoreUpdate to use the keystore:
gen/android/app/build.gradle.ktskotlin
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.propertiesproperties
storePassword=your_store_password
keyPassword=your_key_password
keyAlias=my-app-alias
storeFile=/path/to/release-key.keystore更新以使用该密钥库:
gen/android/app/build.gradle.ktskotlin
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
提交前检查清单
- App signed with release keystore
- Version code incremented from previous release
- App icon configured in all required sizes
- Screenshots prepared (required by Play Store)
- Privacy policy URL ready (required for most apps)
- Content rating questionnaire completed
- 应用已签名:使用发布密钥库签名
- 版本代码已递增:比上一版本更高
- 应用图标已配置:包含所有所需尺寸
- 截图已准备:Play Store要求提供
- 隐私政策URL已准备:多数应用需要
- 内容评级问卷已完成
Upload Process
上传流程
- Navigate to Play Console: https://play.google.com/console/developers
- Create application or select existing app
- Upload AAB file from:
gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab - Complete store listing (title, description, screenshots)
- Set content rating
- Configure pricing and distribution
- Submit for review
- 访问Play Console:https://play.google.com/console/developers
- 创建应用或选择现有应用
- 上传AAB文件,文件路径:
gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab - 完成商店列表(标题、描述、截图)
- 设置内容评级
- 配置定价与分发范围
- 提交审核
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
undefinedAbsolute 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
undefinedstoreFile=../../release-key.keystore
undefinedVersion Code Not Incrementing
版本代码未递增
If using auto-calculation, ensure your or version is updated. For manual control:
package.jsonCargo.tomljson
{
"bundle": {
"android": {
"versionCode": 2
}
}
}如果使用自动计算,请确保或中的版本已更新。如需手动控制:
package.jsonCargo.tomljson
{
"bundle": {
"android": {
"versionCode": 2
}
}
}APK Not Installing on Device
APK无法在设备上安装
Check minimum SDK version compatibility:
bash
undefined检查最低SDK版本兼容性:
bash
undefinedCheck device Android version
检查设备Android版本
adb shell getprop ro.build.version.sdk
undefinedadb shell getprop ro.build.version.sdk
undefinedAAB Too Large
AAB文件过大
Consider using for testing, but for Play Store, Google handles this automatically. If still too large:
--split-per-abi- Optimize your frontend assets
- Use dynamic feature modules
- Enable ProGuard/R8 minification
测试时可以考虑使用,但Play Store会自动处理此问题。如果仍然过大:
--split-per-abi- 优化前端资源
- 使用动态功能模块
- 启用ProGuard/R8代码混淆
Quick Reference
快速参考
Common Build Commands
常用构建命令
bash
undefinedbash
undefinedDevelopment 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
undefinednpm run tauri android build -- --aab --target aarch64
undefinedFile Locations
文件位置
| File | Location |
|---|---|
| AAB output | |
| APK output | |
| Gradle config | |
| Keystore properties | |
| Android manifest | |
| 文件 | 位置 |
|---|---|
| AAB输出文件 | |
| APK输出文件 | |
| Gradle配置文件 | |
| 密钥库属性文件 | |
| Android清单文件 | |