Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial mobile support #924

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open

feat: initial mobile support #924

wants to merge 14 commits into from

Conversation

FabianLars
Copy link
Member

ref #525 (not closing it)

Copy link
Contributor

github-actions bot commented Sep 25, 2024

Package Changes Through 2a2f2a8

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

@fu050409
Copy link

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

@FabianLars
Copy link
Member Author

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...)

@AbandonedCart
Copy link

AbandonedCart commented Nov 18, 2024

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

@fu050409
Copy link

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.

@FabianLars
Copy link
Member Author

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)

@AbandonedCart

This comment was marked as off-topic.

@FabianLars
Copy link
Member Author

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.

@AbandonedCart

This comment was marked as off-topic.

@YuenSzeHong
Copy link

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

@FabianLars
Copy link
Member Author

FabianLars commented Nov 21, 2024

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!)

@YuenSzeHong
Copy link

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

@FabianLars-crabnebula
Copy link

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/

@YuenSzeHong
Copy link

YuenSzeHong commented Nov 22, 2024

    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
Copy link

- 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?

@AbandonedCart
Copy link

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

@YuenSzeHong
Copy link

YuenSzeHong commented Nov 22, 2024

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

@fu050409
Copy link

fu050409 commented Nov 22, 2024

@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?

@YuenSzeHong
Copy link

YuenSzeHong commented Nov 22, 2024

@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.

@FabianLars
Copy link
Member Author

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

@AbandonedCart
Copy link

AbandonedCart commented Nov 22, 2024

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

@FabianLars
Copy link
Member Author

FabianLars commented Nov 22, 2024

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 🤣

@AbandonedCart
Copy link

AbandonedCart commented Nov 22, 2024

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)

@FabianLars
Copy link
Member Author

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).

@AbandonedCart
Copy link

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

@FabianLars
Copy link
Member Author

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.

@AbandonedCart
Copy link

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.

@FabianLars
Copy link
Member Author

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!

@YuenSzeHong
Copy link

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
Copy link

YuenSzeHong commented Nov 24, 2024

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

@FabianLars
Copy link
Member Author

do i need to pass --split-per-abi to get the splits?

No, that just splits the one apk into four.


i assume that you added the args for all or multiple jobs (otherwise the error doesn't make sense) but you have to add it to just the android one. something like this (copied from your workflow above)

      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: 'macos-latest' # ios
            ios: true
            args: ''
          - platform: 'ubuntu-22.04' # desktop linux
            args: ''
          - platform: 'ubuntu-22.04' # android
            android: true
            args: '--apk'
            mobile: true
          - platform: 'windows-latest'
            args: ''

......

      - 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
          includeRelease: ${{ !(matrix.ios || matrix.android) }} # disable desktop builds if we're building for mobile
          includeIOS: ${{ matrix.ios || false }}
          includeAndroid: ${{ matrix.android || false }}
          args: ${{ matrix.args }}

note that i typed it in github so it may contain syntax errors

@YuenSzeHong
Copy link

YuenSzeHong commented Nov 25, 2024

- platform: 'ubuntu-22.04' # desktop linux
  args: ''
- platform: 'ubuntu-22.04' # android
  args: '--apk'
  mobile: true

the second one runs tauri build first then tauri android build, causing my error in the first place, so i moved to single Ubuntu entry with mobile: true with no arguments

so I am wondering how can i pass arguments to tauri android build

@FabianLars
Copy link
Member Author

the second one runs tauri build first then tauri android build, causing my error in the first place, so i moved to single Ubuntu entry with mobile: true with no arguments

This should be taken care of by the includeRelease line in my last message

@FabianLars
Copy link
Member Author

note that all the workflow configs from above are now invalid, i changed the inputs a bit.

i'll worry about testing ios later and added a note to the input saying that it's considered unstable for now.

@AbandonedCart
Copy link

AbandonedCart commented Dec 4, 2024

so I am wondering how can i pass arguments to tauri android build

Here is how I did it:

  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: ''
          - platform: 'windows-latest'
            args: ''
          - platform: 'ubuntu-latest'
            args: '--target aarch64' # arm64-v8a
            android: true
            arch: 'arm64-v8a'
          - platform: 'ubuntu-latest'
            args: '--target armv7' # armeabi-v7a
            android: true
            arch: 'armeabi-v7a'
          - platform: 'ubuntu-latest'
            args: '--target x86_64'
            android: true
            arch: 'x86_64'
          - platform: 'ubuntu-latest'
            args: '--target i686' # x86
            android: true
            arch: 'x86'

I was then able to use the matrix.arch in later conditions. Bear in mind, every build is labeled “universal” for android.

This should be taken care of by the includeRelease line in my last message

Disabling release on mobile actually caused the mobile builds to fail in my tests.

@FabianLars
Copy link
Member Author

Disabling release on mobile actually caused the mobile builds to fail in my tests.

do you have workflow logs for that? the changed workflow in this pr only bulds debug builds and as far as i can see without issues.

@AbandonedCart
Copy link

AbandonedCart commented Dec 4, 2024

I think the issue is that when you opt out of the release, you need to specifically opt into the debug. The error that comes up is that no artifacts were found.

…but then that throws an error that it doesn’t meet YAML specs for the Mac build lol. (Fixed by adding on || false)

yeah, so you have to specifically enable debug alongside disabling release to get an artifact, but not setting anything at all still outputs an unsigned release build.

The only real difference between the two is the output folder and that a debug build is (usually) debuggable. Not setting either parameter seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants