tauri-action icon indicating copy to clipboard operation
tauri-action copied to clipboard

feat: initial mobile support

Open FabianLars opened this issue 1 year ago • 44 comments

ref https://github.com/tauri-apps/tauri-action/issues/525 (not closing it)

FabianLars avatar Sep 25 '24 16:09 FabianLars

Package Changes Through 2a2f2a82549f0aacb51f9f7720471f118386ae7e

No changes.

Add a change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

github-actions[bot] avatar Sep 25 '24 16:09 github-actions[bot]

Any updates on this pull request? Tauri is v2 stable now :D

fu050409 avatar Nov 18 '24 09:11 fu050409

i didn't look into this since my last commit. The main blocker here is stupid iOS again (mostly me not knowing how to set it up so we can test it), but also the user facing config, not too happy with the current includeAndroid/includeIOS approach, that was mostly for easy testing (but can't really think of anything better either...)

FabianLars avatar Nov 18 '24 10:11 FabianLars

includeAndroid / includeIOS isn’t entirely unheard of. In a lot of binaries, they use flags that are nothing more than withModule or usesModule

AbandonedCart avatar Nov 18 '24 17:11 AbandonedCart

Ah...I have to say I can't agree with you more, iOS does cause a lot of trouble (even when built on local machines). Have you ever considered splitting iOS and Android? We can start with a partial solution for Android only, which already solves some of the problems.

fu050409 avatar Nov 19 '24 06:11 fu050409

nah i'll add ios too but let users test it instead of testing it in this repo. Apple gatekeeps .ipa generation behind a (paid?) developer account even though it's literally just a zip file so we can't test it ourselves here yet.

just need to update the search paths, some initial docs and we're good to go. idk if that will happen today but at least this week.

btw, in case someone didn't know, you can use PRs in your own workflow. in this case by replacing tauri-apps/tauri-action@v0 with tauri-apps/tauri-action@mobile (will break once the branch is deleted so using commit hashes instead of the branch name would prob be a good idea)

FabianLars avatar Nov 19 '24 11:11 FabianLars

nah i'll add ios too but let users test it instead of testing it in this repo. Apple gatekeeps .ipa generation behind a (paid?) developer account even though it's literally just a zip file so we can't test it ourselves here yet.

You only need a paid account for entitlements, which usually implies some sort of distribution. You can generate an IPA and test it locally with Xcode for free, so you'd be fine leaving it to the user. Doing it without Xcode is hacky and convoluted, though.

But, the actual reason I was here is...

Android explicitly disabled clear text traffic and enabling it requires access to the manifest. I have yet to find any sort of command or anything that would change it without manually editing the manifest. That more or less makes a completely automated build out of the question. Are there any plans to support something to handle that (down the road)?

AbandonedCart avatar Nov 19 '24 12:11 AbandonedCart

yes, something like this (iirc "patch" files) is planned but mostly unrelated to this repo. This is why the templates don't have the gen/android & gen/apple folders in the .gitignore files at the moment.

FabianLars avatar Nov 19 '24 13:11 FabianLars

Thanks for the info. I had a feeling it may be somewhat unrelated, but also means anyone who needs such edits won't be able to use it. Not your fault, though.

AbandonedCart avatar Nov 19 '24 13:11 AbandonedCart

Any updates on the android support? it has been 2 months since last commit

YuenSzeHong avatar Nov 21 '24 03:11 YuenSzeHong

Android should work. check out the git diff of this pr for an example workflow (it's missing signing which is required to be able to install the APK!)

FabianLars avatar Nov 21 '24 07:11 FabianLars

Android should work. check out the git diff of this pr for an example workflow (it's missing signing which is required to be able to install the APK!)

will the signing be included? looking for that to be also in the workflow

YuenSzeHong avatar Nov 21 '24 09:11 YuenSzeHong

the test workflow probably won't but i'll add something to the docs/example then. For now it's explained here https://v2.tauri.app/distribute/sign/android/

FabianLars-crabnebula avatar Nov 21 '24 12:11 FabianLars-crabnebula

    splits {
        abi {
            isEnable = true
            reset()
            include("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
            isUniversalApk = true
        }
    }

do I add this to my build.gradlew.kts or handle both the universal and the split at the workflow level? or is this supported?

YuenSzeHong avatar Nov 22 '24 03:11 YuenSzeHong

- platform: 'ubuntu-22.04'
  args: '--apk'
  mobile: true
- uses: tauri-apps/tauri-action@3c20edcd47f6c6fa6d7bd17d279e1c1b454ff57d
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  with:
    tagName: v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
    releaseName: 'v__VERSION__'
    releaseBody: 'See the assets to download this version and install.'
    releaseDraft: true
    prerelease: false
    includeAndroid: ${{ matrix.mobile || false }}
    args: ${{ matrix.args }}
Run tauri-apps/tauri-action@3c20edcd47f6c6fa6d7bd17d279e1c1b454ff57d
  with:
    tagName: v__VERSION__
    releaseName: v__VERSION__
    releaseBody: See the assets to download this version and install.
    releaseDraft: true
    prerelease: false
    includeAndroid: true
    args: --apk
    projectPath: .
    includeDebug: false
    includeRelease: true
    includeIOS: false
    includeUpdaterJson: true
    updaterJsonKeepUniversal: false
  env:
    CARGO_HOME: /home/runner/.cargo
    CARGO_INCREMENTAL: 0
    CARGO_TERM_COLOR: always
    CACHE_ON_FAILURE: false
    JAVA_HOME: /opt/hostedtoolcache/Java_Zulu_jdk/17.0.13-11/x64
    JAVA_HOME_17_X64: /opt/hostedtoolcache/Java_Zulu_jdk/17.0.13-11/x64
    ANDROID_HOME: /usr/local/lib/android/sdk
    ANDROID_SDK_ROOT: /usr/local/lib/android/sdk
    GITHUB_TOKEN: ***
running bun [ 'tauri', 'build', '--apk' ]
$ tauri build --apk
error: unexpected argument '--apk' found

  tip: to pass '--apk' as a value, use '-- --apk'

Usage: bun run tauri build [OPTIONS] [ARGS]...

For more information, try '--help'.

is this just me or there is something wrong with my setup?

YuenSzeHong avatar Nov 22 '24 05:11 YuenSzeHong

args: --apk should be -- --apk according to the error

AbandonedCart avatar Nov 22 '24 05:11 AbandonedCart

args: --apk should be -- --apk according to the error

error: unexpected argument '--apk' found

Usage: cargo build [OPTIONS]

For more information, try '--help'.
failed to build app: failed to build app
    Error failed to build app: failed to build app
error: script "tauri" exited with code 1
Error: Command failed with exit code 1: bun tauri build -- --apk

wasted my time, the issue lies on for some reason the includeAndroid is ignored

YuenSzeHong avatar Nov 22 '24 06:11 YuenSzeHong

@YuenSzeHong To be honest, Idk what would you like to do. Tauri use bun tauri android build to create a android apk bundle instead of using --apk, do you mean android build?

fu050409 avatar Nov 22 '24 06:11 fu050409

@YuenSzeHong To be honest, Idk what would you like to do. Tauri use bun tauri android build to create a android apk bundle instead of using --apk, do you mean android build?

@fu050409 well, thats what exactly i want to do, i want to do desktop and android build in same matrix and it don't work

and doesn't tauri android build defaults to aab instead of apk?

name: 'release'

on:
  workflow_dispatch:
  push:
    tags:
      - "v*"

jobs:
  publish-tauri:
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: 'macos-latest' # for Arm based macs (M1 and above).
            args: '--target aarch64-apple-darwin'
          - platform: 'macos-latest' # for Intel based macs.
            args: '--target x86_64-apple-darwin'
          - platform: 'ubuntu-22.04'
            args: ''
            mobile: true
          - platform: 'windows-latest'
            args: ''

    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v4

      - name: install dependencies (ubuntu only)
        if: matrix.platform == 'ubuntu-22.04' # This must match the platform value defined above.
        run: |
          sudo apt-get update
          sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
      - name: setup bun
        uses: oven-sh/setup-bun@v1

      - name: install Rust stable
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: |
            ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}
            ${{ matrix.platform == 'ubuntu-22.04' && 'aarch64-linux-android,armv7-linux-androideabi,i686-linux-android,x86_64-linux-android' || '' }}

      - name: Rust cache
        uses: swatinem/rust-cache@v2
        with:
          workspaces: './src-tauri -> target'

      - name: Setup Java (Android only)
        if: matrix.mobile
        uses: actions/setup-java@v4
        with:
          distribution: 'zulu'
          java-version: '17'

      - name: Setup Android SDK (Android only)
        if: matrix.mobile
        uses: android-actions/setup-android@v3
        
      - name: Install NDK (Android only)
        if: matrix.mobile
        run: sdkmanager "ndk;27.0.11902837"

      - name: setup Android signing (Android only)
        if: matrix.mobile
        run: |
          cd src-tauri/gen/android
          echo "keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}" > keystore.properties
          echo "password=${{ secrets.ANDROID_KEY_PASSWORD }}" >> keystore.properties
          base64 -d <<< "${{ secrets.ANDROID_KEY_BASE64 }}" > $RUNNER_TEMP/keystore.jks
          echo "storeFile=$RUNNER_TEMP/keystore.jks" >> keystore.properties

      - name: install frontend dependencies
        # If you don't have `beforeBuildCommand` configured you may want to build your frontend here too.
        run: bun install # change this to npm or pnpm depending on which one you use.

      - uses: tauri-apps/tauri-action@3c20edcd47f6c6fa6d7bd17d279e1c1b454ff57d
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/27.0.11902837
        with:
          tagName: v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
          releaseName: 'v__VERSION__'
          releaseBody: 'See the assets to download this version and install.'
          releaseDraft: true
          prerelease: false
          includeAndroid: ${{ matrix.mobile || false }}
          args: ${{ matrix.args }}

Update: finally worked, how do I choose to build apk or aab for android? also can I have the splits along with the universal?

I don't really want aab in my release, and I want to include splits in my release, while the current state don't support this.

YuenSzeHong avatar Nov 22 '24 06:11 YuenSzeHong

You will need 2 Ubuntu entries in the matrix. One for desktop and one for mobile with the extra cli args.

FabianLars avatar Nov 22 '24 10:11 FabianLars

wasted my time, the issue lies on for some reason the includeAndroid is ignored

error: unexpected argument '--apk' found

  tip: to pass '--apk' as a value, use '-- --apk'

My apologies, I guess? I diagnosed the error, not the entire build.

You will need 2 Ubuntu entries in the matrix. One for desktop and one for mobile with the extra cli args.

It should be noted somewhere that iOS will only build if runs-on: macos is set.

@YuenSzeHong Also note that the arguments for the splits in tauri are different than the ones used in android studio. They use the same labels as the rust targets

arm64-v8a => aarch64
armeabi-v7a => armv7
x86 => i686 
x86_64 => x86_64

AbandonedCart avatar Nov 22 '24 13:11 AbandonedCart

It should be noted somewhere that iOS will only build if runs-on: macos is set.

Screenshot_20241122-151624.png

This will of course be added to the readme too once I actually update the readme.

Edit: stupid GitHub app didn't want to give me a link to that line so you get a screenshot instead 🤣

FabianLars avatar Nov 22 '24 14:11 FabianLars

It may be easier to flat out say it only runs on macOS runners. I can see someone reading that and being like “well how do I fix that?”

(To be fair, Mac shoots themselves in the foot with the restrictions)

AbandonedCart avatar Nov 22 '24 14:11 AbandonedCart

Hmm yeah, the wording is not final and I will keep that in mind, thanks. Just wanted to make it clear that setting it on the wrong runner won't make the workflow fail (though maybe it should).

FabianLars avatar Nov 22 '24 15:11 FabianLars

error: unrecognized subcommand 'ios' is the error Tauri throws on Linux and that’s easily mistaken for Tauri being broken.

AbandonedCart avatar Nov 22 '24 15:11 AbandonedCart

Yeah, but that is not really relevant for us here. Again, at least with the current plan, the action will ignore the includeIOS setting on Linux/windows and therefore just skip the whole build.

The current implementation may not do that yet, it's a draft after all.

FabianLars avatar Nov 22 '24 16:11 FabianLars

Apologies if my intention was unclear. I am aware it is a draft, but must have missed where it ignores the command on other platforms. Since I don't know your actual plans until they are published, I will hold any comments until it's no longer a draft.

Best of luck.

AbandonedCart avatar Nov 22 '24 16:11 AbandonedCart

Yeah it's probably not in the code yet, but that's what I wanted to say in the screenshot :)

Anyway, thanks for the feedback so far!

FabianLars avatar Nov 22 '24 16:11 FabianLars

You will need 2 Ubuntu entries in the matrix. One for desktop and one for mobile with the extra cli args.

i have tried that, but the flow just failed instead of running the android flow with arguments, i assume the arguments for action should be the same as tauri android build?

YuenSzeHong avatar Nov 24 '24 01:11 YuenSzeHong

do i need to pass --split-per-abi to get the splits? as i previously passed in --apk it failed

YuenSzeHong avatar Nov 24 '24 01:11 YuenSzeHong