# Tauri mobile
Tauri mobile support is in alpha and you can check out the [next branch](https://github.com/tauri-apps/tauri/tree/next) to contribute or see the progress.
## Setting up Android Environment
### 1. Installing JDK
#### Using Android Studio
If you have Android Studio installed, it ships with a version of JDK so you don't have to install it manually. It is usually at `<location of android studio installation>/jre` and can be used for `JAVA_HOME` env var.
You can find it on Windows at `C:\Program Files\Android\Android Studio\jre`
#### Using the terminal
##### Linux/WSL
- Install it by running the following command based on your distro to install JDK:
- debian
```
sudo apt install default-jdk
```
- arch
```
sudo pacman -S jdk-openjdk
```
- Set the `JAVA_HOME` env variable for this current shell (we will make it permanent later on)
```bash
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
```
#### macOS
- Install openjdk with Homebrew:
```
brew install openjdk
```
- Link to system Java wrapper and set the `JAVA_HOME` env:
```
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home"
```
##### Windows
- Download openjdk-11
```powershell
cd $HOME\downloads
Invoke-WebRequest https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip -o openjdk-11.zip
Expand-Archive openjdk-11.zip -d .
mkdir $env:LocalAppData\Java
mv jdk-11.0.2 $env:LocalAppData\Java
```
- Set the `JAVA_HOME` env variable for this current shell (we will make it permanent later on)
```powershell
$env:JAVA_HOME="$env:LocalAppData\Java\jdk-11.0.2"
```
### 2. Installing Android SDK and NDK
There is two ways to install the SDK and NDK.
#### Using Android Studio
You can use the SDK Manager in Android Studio to install:
> Note: you may need to tick `Show Package Details` in the right bottom corner to be abole to see some of these components
1. Android Sdk Platform 33
2. Android SDK Platform-Tools
3. NDK (Side by side) 25.0.8775105
5. Android SDK Build-Tools 33.0.
6. Android SDK Command-line Tools
#### Using the terminal
If you don't want or can't use Android Studio you can still get the SDK Manager CLI quite easily and use it to install other components.
> Note: The SDK Manager is part of the "Command line tools only" that can be downloaded from [here](https://developer.android.com/studio#command-tools)
##### Linux/WSL/macOS
Download the `cmdline-tools`
```bash
cd ~/Downloads
# if you are on Linux/WSL:
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip -O
# if you are on macOS:
wget https://dl.google.com/android/repository/commandlinetools-mac-8512546_latest.zip -O
unzip cmdline-tools.zip
cd cmdline-tools
mkdir latest
mv bin latest/
mv lib latest/
mv NOTICE.txt latest/
mv source.properties latest/
cd ..
mkdir ~/.android # You can use another location for your SDK but I prefer using ~/.android
mv cmdline-tools ~/.android
```
Install required SDK and NDK components
```bash
export ANDROID_HOME="$HOME/.android"
~/.android/cmdline-tools/latest/bin/sdkmanager "platforms;android-33" "platform-tools" "ndk;25.0.8775105" "build-tools;33.0.0"
```
##### Windows
Download the `cmdline-tools`
```powershell
cd $HOME\downloads
Invoke-WebRequest https://dl.google.com/android/repository/commandlinetools-win-8512546_latest.zip -o cmdline-tools.zip
Expand-Archive cmdline-tools.zip -d .
cd cmdline-tools
mkdir latest
mv bin latest/
mv lib latest/
mv NOTICE.txt latest/
mv source.properties latest/
cd ..
mkdir $HOME\.android # You can use another location for your SDK but I prefer using $HOME\.android
mv cmdline-tools $HOME\.android
```
Install required SDK and NDK components
```powershell
$env:ANDROID_HOME="$HOME\.android"
&"$env:ANDROID_HOME\cmdline-tools\latest\bin\sdkmanager.exe" "platforms;android-33" "platform-tools" "ndk;25.0.8775105" "build-tools;33.0.0"
```
> Note: the location you moved the `cmdline-tools` directory into will be the location of your android SDK.
### 3. Setting up Environment Variables
You'll need to set up some environment variables to get everything to work properly. The environment variables below should be all the ones your need to be able to use the Tauri CLI to build/run your Android app.
##### Linux/WSL/macOS
```bash
# .bashrc or .zshrc
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64" # if you are using Android Studio, the location is different, see the section above about JDK
export ANDROID_HOME="$HOME/.android" # if you are using Android Studio, the sdk location will be at `~/Android/Sdk`
export NDK_HOME="$ANDROID_HOME/ndk/25.0.8775105"
```
> For WSL:
> you also need to get ADB to connect to your emulator that is running on Windows
> ```bash
> export WSL_HOST="192.168.1.2" # Run `ipconfig` in windows to get your computer IP
> export ADB_SERVER_SOCKET=tcp:$WSL_HOST:5037
> ```
After updating `.bashrc` either run `source ~/.bashrc` or reopen your terminal to apply the changes.
##### Windows
Open a powershell instance and run the following commands in order
```powershell
Function Add-EnvVar($name, $value) { [System.Environment]::SetEnvironmentVariable("$name", "$value", "User") }
Function Add-PATHEntry($path) { $newPath = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + $path; [System.Environment]::SetEnvironmentVariable("Path", "$newPath", "User") }
Add-EnvVar JAVA_HOME "$env:LocalAppData\Java\jdk-11.0.2" # if you are using Android studio, the location is different, see the section above about JDK
$env:ANDROID_ROOT="$HOME\.android"# if you are using Android studio, the sdk location will be at `$env:LocalAppData\Android\Sdk`
Add-EnvVar ANDROID_HOME "$env:ANDROID_ROOT"
Add-EnvVar NDK_HOME "$env:ANDROID_ROOT\ndk\25.0.8775105"
```
> IMPORTANT: you need to reboot your Windows machine in order for the environement variables to be loaded correctly.
You should now have all the environment variables required and the cmdline-tools available in your PATH. You can verify this by running `$env:ANDROID_ROOT\tools\latest\bin\sdkmanager` which should now be showing its help info.
## Getting Started
Now lets bootstrap a project to develop a Tauri project for mobile.
- Install the Tauri CLI from the next branch by running:
```bash
cargo install --git https://github.com/tauri-apps/tauri --branch next tauri-cli
```
Now you will need a Tauri application project. You can initialize one with create-tauri-app.
### Android
- Go to your Tauri project directory and init the Android project.
``` bash
cd tauri-app
cargo tauri android init
```
### iOS
- Go to your Tauri project directory and init the iOS project.
``` bash
cd tauri-app
cargo tauri ios init
```
## Build and Run on Device
Tauri automatically runs the application on a connected device. If it cannot find one, it will prompt you to select an emulator to use.
### Android
- `cargo tauri android dev`
### iOS
- `cargo tauri ios dev`
## Devtools
Devtools is automatically enabled on development and can be found on Chrome on Android development and on Safari on iOS development.
### Android
Open `chrome://inspect/#devices` in Chrome to get the devtools window.
### iOS
Open Safari > Develop > [Your Device Name] > [Your WebView].