Notes

Since Tauri has been upgraded to v2, this post will primarily focus on version v2.

Project Creation

1
pnpm create tauri-app

Packaging

Icon

Generate icons with various resolutions using the built-in tool in Tauri:

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

Desktop Platform

1
pnpm tauri build

Android Platform

First, initialize the Android project (this will generate the src-tauri/gen/android/app folder):

1
tauri android init

Prerequisites:

Prerequisites

  • Java must be version 17 or higher

  • You need to set ANDROID_HOME and NDK_HOME. You can download via Android Studio and then specify the environment
    variables.

For example, my ANDROID_HOME: D:\applications\sdk\

My NDK_HOME: D:\applications\sdk\ndk\29.0.13113456

1
2
3
tauri android build
# 打包为apk文件
pnpm tauri android build --apk

Points to note when packaging for Android:

You can use the JDK’s built-in signature generator or use the official command. If the .jks file already exists, you
will be prompted to enter the previous key password before generating a new one (it is recommended to create a new jks
file).

1
keytool -genkey -v -keystore $env:USERPROFILE\upload-keystore.jks -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload
- Configuration

Create a keystore.properties file under src-tauri/gen/android.

1
2
3
4
storeFile=upload-keystore.jks # 刚刚生成的文件名
storePassword=123456 # 你指定的密钥
keyAlias=upload # 别名,刚才命令最后一个参数就是 (-alias upload)
keyPassword=123456 # 你指定的密钥

Add the path to the keystore configuration file in the build.gradle.kts file located at src-tauri/gen/android/app/.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
android {
...
signingConfigs {
create("release") {
val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["keyPassword"] as String
storeFile = file(keystoreProperties["storeFile"] as String)
storePassword = keystoreProperties["storePassword"] as String
}
}
...

buildTypes {
getByName("debug") {
...
}
getByName("release") {
signingConfig = signingConfigs.getByName("release")
...
}
}
}
  • Gradle Dependency Download Timeout Issues

Modify the .kts files under src-tauri/gen/android.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
buildscript {
repositories {
mavenCentral()

maven { url= uri("https://maven.aliyun.com/repository/google")}
maven { url= uri("https://maven.aliyun.com/repository/gradle-plugin")}
maven { url = uri("https://maven.aliyun.com/repository/public") }

// maven { url= uri("http://maven.aliyun.com/nexus/content/groups/public/")}
maven { url= uri("https://maven.aliyun.com/repository/google")}
// maven { url = uri("http://maven.aliyun.com/nexus/content/repositories/jcenter") }
// flatDir { dirs("libs") }
google()
}
dependencies {

classpath("com.android.tools.build:gradle:8.5.1")
// classpath("com.android.tools.build:gradle:8.9")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.25")
}
}

allprojects {
repositories {

maven { url= uri("https://maven.aliyun.com/repository/google")}
maven { url= uri("https://maven.aliyun.com/repository/gradle-plugin")}
maven { url = uri("https://maven.aliyun.com/repository/public") }

// maven { url= uri("http://maven.aliyun.com/nexus/content/groups/public/")}
maven { url= uri("https://maven.aliyun.com/repository/google")}
// maven { url = uri("http://maven.aliyun.com/nexus/content/repositories/jcenter") }

// flatDir { dirs("libs") }
// maven { url= uri("https://maven.aliyun.com/repository/google")}
// maven { url= uri("https://maven.aliyun.com/repository/gradle-plugin")}
// maven { url = uri("https://maven.aliyun.com/repository/public") }
google()
mavenCentral()
}
}

tasks.register("clean").configure {
delete("build")
}


  • The output location for the packaged APK file is: src-tauri\gen\android\app\build\outputs\apk\universal\release

Embedded Platforms

Not yet covered.


本站总访问量