Skip to content

Commit

Permalink
chore: change tauri-mobile to cargo-mobile2 (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Oct 4, 2023
1 parent a179e37 commit 2d62f36
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
144 changes: 72 additions & 72 deletions MOBILE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Mobile Setup for Wry

We use [tauri-mobile](https://github.com/tauri-apps/tauri-mobile) to create a mobile project for both Xcode and Android studio.
We use [cargo-mobile2](https://github.com/tauri-apps/cargo-mobile2) to create a mobile project for both Xcode and Android studio.

## Prerequisite

Expand All @@ -12,7 +12,8 @@ We use [tauri-mobile](https://github.com/tauri-apps/tauri-mobile) to create a mo
### 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 `<path of android studio installation>/jre`. It will be used for `JAVA_HOME` env var.

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 `<path of android studio installation>/jre`. It will be used for `JAVA_HOME` env var.

> On macOS, it can be found at `/Applications/Android\ Studio.app/Contents/jbr/Contents/Home`
> On Windows, it can be found at `C:\Program Files\Android\Android Studio\jre`
Expand All @@ -23,19 +24,19 @@ If you have Android Studio installed, it ships with a version of JDK so you don'

- Install it by running the following command based on your distro to install JDK:

- debian-based
```
sudo apt install default-jdk
```
- arch-based
```
sudo pacman -S jdk-openjdk
```
- debian-based
```
sudo apt install default-jdk
```
- arch-based
```
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"
```
```bash
export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
```

#### macOS

Expand All @@ -55,22 +56,21 @@ 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
```
```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"
```

```powershell
$env:JAVA_HOME="$env:LocalAppData\Java\jdk-11.0.2"
```

### 2. Installing Android SDK and NDK

There are two ways to install the sdk and ndk.
There are two ways to install the sdk and ndk.

#### Using Android Studio:

Expand All @@ -79,8 +79,8 @@ You can use the SDK Manager in Android Studio to install:
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
4. Android SDK Build-Tools 33.0.
5. Android SDK Command-line Tools

> Note: you may need to tick `Show Package Details` in the right bottom corner to be able to see some of these components
Expand All @@ -98,8 +98,8 @@ Download the `cmdline-tools`
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-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
Expand Down Expand Up @@ -153,10 +153,9 @@ $env:ANDROID_HOME="$HOME\.android"

> 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 [tauri-mobile](https://github.com/tauri-apps/tauri-mobile) to build/run your android app.
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 [cargo-mobile2](https://github.com/tauri-apps/cargo-mobile2) to build/run your android app.

##### Linux/WSL/macOS

Expand All @@ -173,7 +172,6 @@ export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home

- Setting `ANDROID_HOME`:


```bash
export ANDROID_HOME="$HOME/.android"
# If you are using Android studio, on Linux, it is:
Expand All @@ -184,7 +182,6 @@ export ANDROID_HOME="$HOME/Library/Android/sdk"

- Setting `PATH`:


```bash
export NDK_HOME="$ANDROID_HOME/ndk/25.0.8775105" # The patch version might be different
export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin"
Expand All @@ -193,10 +190,11 @@ export PATH="$PATH:$ANDROID_HOME/platform-tools"

> 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
> ```
>
> ```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.
Expand All @@ -210,53 +208,56 @@ Function Add-PATHEntry($path) { $newPath = [System.Environment]::GetEnvironmentV
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:SDK_ROOT="$HOME\.android"# if you are using Android studio, the sdk location will be at `$env:LocalAppData\Android\Sdk`
Add-EnvVar ANDROID_HOME "$env:SDK_ROOT"
Add-EnvVar ANDROID_HOME "$env:SDK_ROOT"
Add-EnvVar NDK_HOME "$env:SDK_ROOT\ndk\25.0.8775105"
Add-PATHEntry "$env:SDK_ROOT\cmdline-tools\latest\bin"
Add-PATHEntry "$env:SDK_ROOT\platform-tools"
```
> IMPORTANT: you need to reboot your Windows machine in order for the environement variables to be loaded correctly.
> 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 `sdkmanager` which should now be showing its help info.
### 4. Install Rust android targets:
```shell
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
```
```
## Getting Started
Now lets bootstrap a project to develop a tauri or wry project for mobile.
- Install [tauri-mobile](https://github.com/tauri-apps/tauri-mobile) CLI by running:
```bash
cargo install --git https://github.com/tauri-apps/tauri-mobile
```
- Install [cargo-mobile2](https://github.com/tauri-apps/cargo-mobile2) CLI by running:
```bash
cargo install --git https://github.com/tauri-apps/cargo-mobile2
```
- Create a directory and init the project.
``` bash
mkdir hello
cd hello
cargo mobile init
# Project name (hello):
# Stylized name (Hello):
# Domain (example.com): tauri.app
# Detected template packs:
# [0] bevy
# [1] bevy-demo
# [2] wgpu
# [3] winit
# [4] wry
# Enter an index for a template pack above.
# Template pack (0): 4
```
```bash
mkdir hello
cd hello
cargo mobile init
# Project name (hello):
# Stylized name (Hello):
# Domain (example.com): tauri.app
# Detected template packs:
# [0] bevy
# [1] bevy-demo
# [2] wgpu
# [3] winit
# [4] wry
# Enter an index for a template pack above.
# Template pack (0): 4
```
## Build and Run on Device
### Android
> Make sure you're device is connected to adb
> you can check by running `cargo android list` or `adb devices`
- `cargo android run`
### iOS
Expand All @@ -270,15 +271,15 @@ First time running the app will be blocked. Go to your phone's `Settings > Priva
### Android
##### Using Android Studio
##### Using Android Studio
- Open the project in Android Studio `cargo android open`
- Click `Trust Project`, `Use Embedded JDK`
- Choose an emulator. I usually choose Pixel 4 API 32
- (optional) if you face this error `Device supports x86, but APK only supports armeabi-v7a` then check this [Stack Overflow answer](https://stackoverflow.com/questions/41775988/what-is-the-reason-for-the-error-device-supports-x86-but-apk-only-supports-arm/43742161#43742161) to fix it.
- Press run button.
##### Without Android Studio
##### Without Android Studio
If you don't have access to Android Studio or don't want or when running in WSL, you can build and run the generated project directly from the terminal
Expand All @@ -291,11 +292,11 @@ If you don't have access to Android Studio or don't want or when running in WSL,
```powershell
&"$env:ANDROID_HOME\emulator\emulator" -list-avds
```
you should now see a list of available emulators like the following, you'll need one of them for the next step:
```
Resizable_API_33
Pixel_5_API_33
```
you should now see a list of available emulators like the following, you'll need one of them for the next step:
```
Resizable_API_33
Pixel_5_API_33
```
2. Start the emulator with the name of the desired emulator:
- Linux/WSL/macOS:
```bash
Expand All @@ -306,10 +307,9 @@ If you don't have access to Android Studio or don't want or when running in WSL,
&"$env:ANDROID_HOME\emulator\emulator" -avd Resizable_API_33
```
3. In a new terminal window, run:
```bash
cargo android run
```
```bash
cargo android run
```
### iOS
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ WebView2 provided by Microsoft Edge Chromium is used. So wry supports Windows 7,

### Android / iOS

Wry supports mobile with the help of [`tauri-mobile`](https://github.com/tauri-apps/tauri-mobile) CLI to create template project. If you are interested in playing or hacking it, please follow [MOBILE.md](MOBILE.md).
Wry supports mobile with the help of [`cargo-mobile2`](https://github.com/tauri-apps/cargo-mobile2) CLI to create template project. If you are interested in playing or hacking it, please follow [MOBILE.md](MOBILE.md).

If you wish to create Android project yourself, there are a few kotlin files that are needed to run wry on Android and you have to set the following environment variables:

Expand Down

0 comments on commit 2d62f36

Please sign in to comment.