Astro on Android with Tauri
This guide will walk you through how to setup a Astrojs Project primarily for Android Support using Tauri.
Guide is tailored to work on these Operating Systems and shells
| OS | Debian | Ubuntu | Antix | Arch |
| Shell | Bash | ZSH | Fish |
Prerequisites
- You need to have an App Icon Ready in either
.svg,.pngor.jpgformat in you[project]/public/folder - As of today, tauri doesn’t fully support
SSRmode in astrojs. so to be on the safe side, you need to be on theSSGmode for eveything
Tooling Setup
-
Install Rust and System Depedencies
Terminal window sudo apt updatesudo apt install libwebkit2gtk-4.1-dev \build-essential \curl \wget \file \libxdo-dev \libssl-dev \libayatana-appindicator3-dev \librsvg2-devcurl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh &&rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-androidTerminal window sudo pacman -Syusudo pacman -S webkit2gtk \base-devel \curl \wget \file \libxdo \openssl \libayatana-appindicator \librsvgcurl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh &&rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android -
Setup Android Studio
Download and Install Android Studio
Extract it into the
/opt/directory in linuxTerminal window sudo tar -xvf ~/Downloads/android-studio-2024.3.1.14-linux.tar.gz -C /opt/run this to setup all your environment variables
Terminal window cat << 'EOF' >> ~/.bashrcexport PATH="$PATH:/opt/android-studio/bin"export JAVA_HOME=/opt/android-studio/jbrexport ANDROID_HOME="$HOME/Android/Sdk"export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)"EOFTerminal window cat << 'EOF' >> ~/.zshrcexport PATH="$PATH:/opt/android-studio/bin"export JAVA_HOME=/opt/android-studio/jbrexport ANDROID_HOME="$HOME/Android/Sdk"export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)"EOFTerminal window fish_add_path /opt/android-studio/binset -Ux ANDROID_HOME $HOME/Android/Sdkset -Ux NDK_HOME $ANDROID_HOME/ndkset -Ux JAVA_HOME /opt/android-studio/jbrNow Open up Android Studio with this commnad
Terminal window studioOpen up SDK Manager from
More Action > SDK Managerand install the following:SDK Platforms > Android <version> ("<Code>")(Adnroid 10.0 (“Q”) will work)SDK Tools > Android SDK Build-Tools <version>SDK Tools > NDK (Side by side)SDK Tools > Android SDK Command-line Tools (latest)SDK Tools > Android SDK Platform Tools
Now, Add
Android Studioas an Desktop Application that shows up in App Selection Menues Across the OSTerminal window # Step 1: Create the desktop entry directory if it doesn't existmkdir -p ~/.local/share/applicationscat > ~/.local/share/applications/android-studio.desktop << 'EOF'[Desktop Entry]Version=1.0Type=ApplicationName=Android StudioComment=Android Studio IDEExec=/opt/android-studio/bin/studio.shIcon=/opt/android-studio/bin/studio.pngCategories=Development;IDE;Terminal=falseStartupWMClass=jetbrains-studioEOFchmod +x ~/.local/share/applications/android-studio.desktopupdate-desktop-database ~/.local/share/applications
Build Your AstroJs Android App!
I recommend initializing Tauri mannualy instead of using a Preconfigured Template because of several automation tricks built into the Tauri CLI that make your required configs easy to configure (eg. seeting up name, icons, etc). so this guide will assume that you have already initialized your astrojs project
-
Initialize Tauri
Terminal window bun add -D @tauri-apps/cli@latest &&bun tauri initFill in the Options that it asks
✔ What is your app name? astrojs-tauri✔ What should the window title be? astrojs-tauri✔ Where are your web assets located? ../dist✔ What is the url of your dev server? http://localhost:4321✔ What is your frontend dev command? bun dev✔ What is your frontend build command? bun run buildEdit the
IdentifierProperty in./src-tauri/tauri.conf.jsonFile with the project name without spaces like this{//..."version": "0.1.0","identifier": "com.tauri.dev","identifier": "com.<project-name>.dev","build": {//...}//...} -
Setup Tauri for Android Support
Initialize Android Target
Terminal window bun tauri android initgive it the Icon’s Path
Terminal window bun tauri icon ./public/logo.svgCode Signing
run this and fill out all all options correctly
Terminal window /opt/android-studio/jbr/bin/keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias uploadCreate a file named
src-tauri/gen/android/keystore.propertiesand add content according to this templatepassword=<password defined when keytool was executed>keyAlias=uploadstoreFile=<location of the key store file, such as /Users/<user name>/upload-keystore.jks>Edit the
src-tauri/gen/android/app/build.gradle.ktsfile and do the following- Add the needed import at the beginning of the file:
import java.io.FileInputStream
- Add the release signing config before the buildTypes block:
defaultConfig {...}signingConfigs {create("release") {val keystorePropertiesFile = rootProject.file("keystore.properties")val keystoreProperties = Properties()if (keystorePropertiesFile.exists()) {keystoreProperties.load(FileInputStream(keystorePropertiesFile))}keyAlias = keystoreProperties["keyAlias"] as StringkeyPassword = keystoreProperties["password"] as StringstoreFile = file(keystoreProperties["storeFile"] as String)storePassword = keystoreProperties["password"] as String}}buildTypes {...}
- Use the new release signing config in the release config in buildTypes block:
buildTypes {getByName("debug") {...}getByName("release") {signingConfig = signingConfigs.getByName("release")...}}
- Add the needed import at the beginning of the file:
-
Build the APK
Terminal window bun tauri android build --apk --target aarch64APK will be present at
./src-tauri/gen/android/app/build/outputs/apk/universal/releasecd and share it with Nemo File ExplorerTerminal window cd "./src-tauri/gen/android/app/build/outputs/apk/universal/release"nemo .