tauri-apps / tauri-action

Build your Web application as a Tauri binary for macOS, Linux and Windows
https://tauri.app
MIT License
938 stars 154 forks source link

[Feature Request] Add mobile build support #525

Open developomp opened 1 year ago

developomp commented 1 year ago

Currently, there's no way to build mobile apps using the tauri-action workflow, and since I can't find discussions of it anywhere, I would like to start one here:

tauri-action automatically build apps for specific platform based on the OS. And since mobile apps has to be compiled from desktop OS, I think adding a mobile option sounds like a decent solution.

Here's an example of how the mobile build workflow might look like:

...
jobs:
  release:
    strategy:
      matrix:
        platform: [macos-latest, ubuntu-20.04, windows-latest]
        mobile: no
        include: # https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
          - os: ubuntu-latest
            mobile: yes
          - os: macos-latest
            mobile: yes
      ...

      - uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tagName: app-v__VERSION__
          releaseName: 'App v__VERSION__'
          mobile: ${{ matrix.mobile }} # <- HERE
          releaseDraft: true
          prerelease: false
FabianLars commented 1 year ago

Yes, this is planned though i don't know yet how far we can really get in CI but we'll see. There's currently no mobile/v2 support because i'm waiting for it to be a bit more stable (at least beta) so we don't have to redo it every second week.

liudonghua123 commented 1 year ago

I also like this feature. Looking forward to beta/stable of tauri 2.0.

jbeuria commented 8 months ago

Is building mobile apps using the tauri-action workflow implemented now in the beta version?

FabianLars commented 8 months ago

If that were the case, this issue would be closed.

haleksandre commented 5 months ago

It is possible to build Android apps by modifying the tauriScript command to something along the lines of npx tauri android but then the step fails because it can't find the artifacts.

# building...
# compiling...
    Finished 1 APK at:
        /home/runner/work/test-tauri/test-tauri/src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk

    Finished 1 AAB at:
        /home/runner/work/test-tauri/test-tauri/src-tauri/gen/android/app/build/outputs/bundle/universalRelease/app-universal-release.aab

Looking for artifacts in:
/home/runner/work/test-tauri/test-tauri/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle/deb/***bracket_0.0.1_amd64.deb
/home/runner/work/test-tauri/test-tauri/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle/rpm/***bracket-0.0.1-1.x86_64.rpm
/home/runner/work/test-tauri/test-tauri/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle/appimage/***bracket_0.0.1_amd64.AppImage
/home/runner/work/test-tauri/test-tauri/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle/appimage/***bracket_0.0.1_amd64.AppImage.tar.gz
/home/runner/work/test-tauri/test-tauri/src-tauri/target/x86_64-unknown-linux-gnu/release/bundle/appimage/***bracket_0.0.1_amd64.AppImage.tar.gz.sig
Error: No artifacts were found.

Technically the action only needs a way to modify the platform check below & append the the apk/aad paths to the artifacts variable if the build is Android. https://github.com/tauri-apps/tauri-action/blob/a32a76cf0a532b3e3b8d0cfb6039e2d574aace68/src/build.ts#L90-L236

Is this something you'd be willing to add relatively soon or you'd still prefer to wait for a more stable Tauri 2.0?

RoseBlume commented 5 months ago

This would be nice, for now im stuck using a selfhosted runner for this.

francollamas commented 3 months ago

I can share my Github Action as "workarround" to build signed APK files, for anyone interested on it. I know it probably doesn't have the best practices and it isn't optimized either, but it works for me for the moment. It makes use of another GH actions.

To make it works, you need to set this environments variables on your github project: ANDROID_RELEASE_KEYSTORE --> your keystore file encoded in base64 ANDROID_RELEASE_PASSWORD --> the keystore password ANDROID_RELEASE_KEY --> the name of the Key ANDROID_RELEASE_KEY_PASSWORD --> the password for that Key

name: 'publish'

on:
    push:
        branches:
            - release

    workflow_dispatch:

jobs:
    publish-android:
        runs-on: ubuntu-latest
        permissions:
            contents: write
        steps:
            - uses: actions/checkout@v4

            - uses: pnpm/action-setup@v4
              with:
                  version: 8

            - name: Setup Java
              uses: actions/setup-java@v4
              with:
                  distribution: 'zulu'
                  java-version: '17'

            - name: Setup Android SDK
              uses: android-actions/setup-android@v3

            - name: Install NDK
              run: sdkmanager "ndk;27.0.11902837"

            - name: setup node
              uses: actions/setup-node@v4
              with:
                  node-version: lts/*

            - name: install Rust stable
              uses: dtolnay/rust-toolchain@stable
              with:
                  targets: aarch64-linux-android,armv7-linux-androideabi,i686-linux-android,x86_64-linux-android

            - name: Install dependencies
              run: pnpm install

            - name: Build app bundle
              run: pnpm tauri android build -v
              env:
                  NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/27.0.11902837

            - name: Extract android signing key from env
              run: |
                  echo "${{ secrets.ANDROID_RELEASE_KEYSTORE }}" > src-tauri/gen/android/release.jks.base64
                  base64 -d src-tauri/gen/android/release.jks.base64 > src-tauri/gen/android/release.decrypted.jks

            - name: Sign APK
              run: |
                  ${{ env.ANDROID_HOME }}/build-tools/34.0.0/apksigner sign --ks src-tauri/gen/android/release.decrypted.jks \
                    --ks-key-alias ${{ secrets.ANDROID_RELEASE_KEY }} \
                    --ks-pass pass:${{ secrets.ANDROID_RELEASE_PASSWORD }} \
                    --key-pass pass:${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }} \
                    --out src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-signed.apk \
                    src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk

            - name: Get Node project version
              id: package-version
              uses: martinbeentjes/npm-get-version-action@v1.3.1

            - name: Rename APK file
              run: |
                  mv ./src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-signed.apk ./src-tauri/gen/android/app/build/outputs/apk/universal/release/myappliation-${{ steps.package-version.outputs.current-version}}.apk

            - name: Publish
              uses: softprops/action-gh-release@v1
              with:
                  draft: true
                  name: App v${{ steps.package-version.outputs.current-version}}
                  tag_name: v${{ steps.package-version.outputs.current-version}}
                  generate_release_notes: true
                  files: |
                      ./src-tauri/gen/android/app/build/outputs/apk/universal/release/myapplication-${{ steps.package-version.outputs.current-version}}.apk
nyxb commented 2 months ago

I can share my Github Action as "workarround" to build signed APK files, for anyone interested on it. I know it probably doesn't have the best practices and it isn't optimized either, but it works for me for the moment. It makes use of another GH actions.

To make it works, you need to set this environments variables on your github project: ANDROID_RELEASE_KEYSTORE --> your keystore file encoded in base64 ANDROID_RELEASE_PASSWORD --> the keystore password ANDROID_RELEASE_KEY --> the name of the Key ANDROID_RELEASE_KEY_PASSWORD --> the password for that Key

name: 'publish'

on: push: branches:

  • release

    workflow_dispatch:

jobs: publish-android: runs-on: ubuntu-latest permissions: contents: write steps:

  • uses: actions/checkout@v4

  • uses: pnpm/action-setup@v4 with: version: 8

  • name: Setup Java uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: '17'

  • name: Setup Android SDK uses: android-actions/setup-android@v3

  • name: Install NDK run: sdkmanager "ndk;27.0.11902837"

  • name: setup node uses: actions/setup-node@v4 with: node-version: lts/*

  • name: install Rust stable uses: dtolnay/rust-toolchain@stable with: targets: aarch64-linux-android,armv7-linux-androideabi,i686-linux-android,x86_64-linux-android

  • name: Install dependencies run: pnpm install

  • name: Build app bundle run: pnpm tauri android build -v env: NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/27.0.11902837

  • name: Extract android signing key from env run: | echo "${{ secrets.ANDROID_RELEASE_KEYSTORE }}" > src-tauri/gen/android/release.jks.base64 base64 -d src-tauri/gen/android/release.jks.base64 > src-tauri/gen/android/release.decrypted.jks

  • name: Sign APK run: | ${{ env.ANDROID_HOME }}/build-tools/34.0.0/apksigner sign --ks src-tauri/gen/android/release.decrypted.jks \ --ks-key-alias ${{ secrets.ANDROID_RELEASE_KEY }} \ --ks-pass pass:${{ secrets.ANDROID_RELEASE_PASSWORD }} \ --key-pass pass:${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }} \ --out src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-signed.apk \ src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk

  • name: Get Node project version id: package-version uses: martinbeentjes/npm-get-version-action@v1.3.1

  • name: Rename APK file run: | mv ./src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-signed.apk ./src-tauri/gen/android/app/build/outputs/apk/universal/release/myappliation-${{ steps.package-version.outputs.current-version}}.apk

  • name: Publish uses: softprops/action-gh-release@v1 with: draft: true name: App v${{ steps.package-version.outputs.current-version}} tag_name: v${{ steps.package-version.outputs.current-version}} generate_release_notes: true files: | ./src-tauri/gen/android/app/build/outputs/apk/universal/release/myapplication-${{ steps.package-version.outputs.current-version}}.apk

Do you have something like this in stock for ios?