setup-android icon indicating copy to clipboard operation
setup-android copied to clipboard

Has this been tried on arm64 runners?

Open pbrewer-ifit opened this issue 2 years ago • 13 comments

I am trying to use this package to set up self-hosted runners on arm64 AWS instances.

I get the following error and the setup-android step ends after the following:

[===                                    ] 10% Computing updates...              
[845](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:845)
                                                                                
[846](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:846)
Warning: Unable to compute a complete list of dependencies.
[847](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:847)
(node:5271) UnhandledPromiseRejectionWarning: Error: The process '/home/ec2-user/.android/sdk/cmdline-tools/6.0/bin/sdkmanager' failed with exit code 1
[848](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:848)
    at ExecState._setResult (/opt/actions-runner/_work/_actions/android-actions/setup-android/v2/dist/index.js:1307:25)
[849](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:849)
    at ExecState.CheckComplete (/opt/actions-runner/_work/_actions/android-actions/setup-android/v2/dist/index.js:1290:18)
[850](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:850)
    at ChildProcess.<anonymous> (/opt/actions-runner/_work/_actions/android-actions/setup-android/v2/dist/index.js:1184:27)
[851](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:851)
    at ChildProcess.emit (events.js:314:20)
[852](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:852)
    at maybeClose (internal/child_process.js:1022:16)
[853](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:853)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
[854](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:854)
(node:5271) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
[855](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:855)
(node:5271) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[856](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:6:856)
[===                                    ] 10% Computing updates...

and then later it appears the SDK is either not installed or the environment variables aren't configured, because I see:

Could not determine the dependencies of task ':my-hotfix-module:lintDebug'.
[306](https://github.com/my-hotfix-module/runs/6230451597?check_suite_focus=true#step:9:306)
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable

How can I confirm the SDK is installed, and if it is and I need to set the environment var myself, where is the SDK installed?

pbrewer-ifit avatar Apr 29 '22 15:04 pbrewer-ifit

If install succeeds, you should be able to run sdkmanager binary, it should be in the $PATH.

- uses: android-actions/setup-android@v2
- run: sdkmanager --list

I have not tried this on arm64 and don't have access to hardware to test it out. sdkmanager, as far as I know, is a regular java program, should just work. Key word being should, not must. If things are weird, would suggest you to try and install Command line tools manually and verify that they do actually work on arm64 box without adding GitHub runner into the mix.

ViliusSutkus89 avatar Apr 29 '22 18:04 ViliusSutkus89

It does look like parts of the SDK might not be available for Linux arm64. I thought everything was 100% java, but guess that is not true.

I understand not having linux arm64 hardware. On AWS a reasonable server can be had for testing for $0.04 to $0.08 per hour. An afternoon's work could be had for a fraction of a $1. I'm sure people would be happy to chip in a little for AWS machine time. Or hit AWS up for free time to get more software running on their ARM servers. Just a thought.

pbrewer-ifit avatar Apr 29 '22 20:04 pbrewer-ifit

No hardware was more of a $genericExcuse. I would look into it, but I have stuff to do. This requires setting up EC2, verifying that sdkmanager actually works there, setting up a self-hosted GitHub runner. Sounds like an afternoon of effort.

Pull Requests more than welcome though.

ViliusSutkus89 avatar Apr 29 '22 22:04 ViliusSutkus89

I just ran into this today, I was trying to run a workflow with act-js (GHA workflow testing framework) on Mac with M2, and it uses a Docker image that doesn't have all the preinstalled dependencies that normal runners do, i.e. no Java and no Android SDK (not even cmdline-tools)

The problem as I understood is essentially that tools depends on emulator, but for the architecture of the runner image there's no emulator available. This means that the basic setup of tools just does not work. The key phrase that's somehow missing from OP is "Dependant package with key emulator not found!", if you google that there's a ton of similar issues, some with workarounds, e.g. https://stackoverflow.com/q/71545278/253468

Having the emulator package.xml pre-exist in the right folder makes setup-android pass the setup. If the emulator is not actually used during the build, then this workaround is fine. Some SO answer said that the problem is that the ARM64 emulator package is only available in canary channels.

TWiStErRob avatar Nov 21 '23 21:11 TWiStErRob

I see. We install tools package by default. I think the proper way would be to add another input variable for this action, to control which packages are installed by default, so that it would be possible to skip tools install and do it only after the canary emulator is available:

- name: Setup Android SDK
  uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools' # instead of the default 'tools platform-tools'

- run: sdkmanager --channel=3 emulator
- run: sdkmanager tools

ViliusSutkus89 avatar Nov 21 '23 21:11 ViliusSutkus89

That would be useful regardless of this issue! e.g. this setup could be simplified a lot.

Alternatively, specifically for this issue, you might also consider downloading and installing the right emulator for the right architecture so people never ever run into this issue. Sadly on GH-hosted runners it's not possible to test this :(

TWiStErRob avatar Nov 21 '23 21:11 TWiStErRob

Can't do it today, but I'll implement the package list soon. (Unless you want to do it yourself :D ). I don't have access to a Mac, so you'll have to check if the canary emulator workaround actually works, before we put it here

ViliusSutkus89 avatar Nov 21 '23 21:11 ViliusSutkus89

Is there any branch or pre-release to test. When do you plan to release?

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools' # instead of the default 'tools platform-tools'
- run: sdkmanager --channel=3 emulator
- run: sdkmanager tools

On arm64 runner, using action android-actions/setup-android v2 or v3, not able complete Android SDK setup.

Warning: Dependant package with key emulator not found!
Warning: Unable to compute a complete list of dependencies.
[===                                    ] 10% Computing updates...              
                                                                                
/runner/_work/_actions/android-actions/setup-android/v3/dist/index.js:2348
                error = new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`);
                        ^

Error: The process '/home/runner/.android/sdk/cmdline-tools/10.0/bin/sdkmanager' failed with exit code 1
    at ExecState._setResult (/runner/_work/_actions/android-actions/setup-android/v3/dist/index.js:2348:25)
    at ExecState.CheckComplete (/runner/_work/_actions/android-actions/setup-android/v3/dist/index.js:2[33](https://github.com/fieldnation/fn_react_native/actions/runs/6987847358/job/19014874534#step:6:34)1:18)
    at ChildProcess.<anonymous> (/runner/_work/_actions/android-actions/setup-android/v3/dist/index.js:2225:27)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)

juliusiqbalfn avatar Nov 25 '23 09:11 juliusiqbalfn

v3.2.0 is available. @TWiStErRob , @juliusiqbalfn , can y'all check if this usecase works?

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools' # instead of the default 'tools platform-tools'
- run: sdkmanager --channel=3 emulator
- run: sdkmanager tools

ViliusSutkus89 avatar Nov 25 '23 16:11 ViliusSutkus89

v3.2.0 is available. @TWiStErRob , @juliusiqbalfn , can y'all check if this usecase works?

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools' # instead of the default 'tools platform-tools'
- run: sdkmanager --channel=3 emulator
- run: sdkmanager tools

There are use cases but still fails with emulator not found in arm64 runner w/o channel argument.

Warning: Failed to find package 'emulator'
[===                                    ] 10% Computing updates...              
                                                                                
[===                                    ] 10% Computing updates...              
Error: Process completed with exit code 1.

Below commands listed no emulator packages.

sdkmanager --list
sdkmanager --list --channel=3

juliusiqbalfn avatar Nov 25 '23 17:11 juliusiqbalfn

v3.2.0 is available. @TWiStErRob , @juliusiqbalfn , can y'all check if this usecase works?

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools' # instead of the default 'tools platform-tools'
- run: sdkmanager --channel=3 emulator
- run: sdkmanager tools

There are use cases but still fails with emulator not found in arm64 runner w/o channel argument.

Warning: Failed to find package 'emulator'
[===                                    ] 10% Computing updates...              
                                                                                
[===                                    ] 10% Computing updates...              
Error: Process completed with exit code 1.

Below commands listed no emulator packages.

sdkmanager --list
sdkmanager --list --channel=3

I am now able to complete setup with below commands.

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools'
- run: |
    curl --location --output emulator.zip https://redirector.gvt1.com/edgedl/android/repository/emulator-darwin_aarch64-10696886.zip
    unzip -d /path/to/android-sdk -n emulator.zip
    rm -f emulator.zip
    cp /path/to/android-sdk/platform-tools/package.xml /path/to/android-sdk/emulator/package.xml
    sed -i \
      -e 's|path="[a-zA-Z-]*"|path="emulator"|g' \
      -e 's|<major>[0-9]*<\/major>|<major>32<\/major>|g' \
      -e 's|<minor>[0-9]*<\/minor>|<minor>1<\/minor>|g' \
      -e 's|<micro>[0-9]*<\/micro>|<micro>15<\/micro>|g' \
      -e 's|<display-name>Android .*<\/display-name>|<display-name>Android Emulator<\/display-name>|g' \
      /path/to/android-sdk/emulator/package.xml
- run: sdkmanager tools

Still fails with below errors, working on that

emulator: cannot execute binary file: Exec format error
adb: cannot execute binary file: Exec format error

Might try

https://ci.android.com/builds/submitted/10696670/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-10696670.zip

Instead of

https://redirector.gvt1.com/edgedl/android/repository/emulator-darwin_aarch64-10696886.zip

juliusiqbalfn avatar Nov 29 '23 18:11 juliusiqbalfn

@remixer-dec previously linked an issue ( https://github.com/741g/android-emulator-m1-preview/issues/14#issuecomment-1515696128 ) which documents build-tools;30.0.3 having a dependency on emulator. Later build-tools versions don't have that dependency anymore.

I suggest you could try uninstalling "build-tools;30.0.3", but in that case you won't be able to build Android projects which want to compile on SDK 30 (compile, not target).

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools' # instead of the default 'tools platform-tools'
- run: sdkmanager --uninstall "build-tools;30.0.3"
- run: sdkmanager tools

(I should just get an arm VM instead...)

ViliusSutkus89 avatar Nov 29 '23 21:11 ViliusSutkus89

v3.2.0 is available. @TWiStErRob , @juliusiqbalfn , can y'all check if this usecase works?

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools' # instead of the default 'tools platform-tools'
- run: sdkmanager --channel=3 emulator
- run: sdkmanager tools

There are use cases but still fails with emulator not found in arm64 runner w/o channel argument.

Warning: Failed to find package 'emulator'
[===                                    ] 10% Computing updates...              
                                                                                
[===                                    ] 10% Computing updates...              
Error: Process completed with exit code 1.

Below commands listed no emulator packages.

sdkmanager --list
sdkmanager --list --channel=3

I am now able to complete setup with below commands.

- uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools'
- run: |
    curl --location --output emulator.zip https://redirector.gvt1.com/edgedl/android/repository/emulator-darwin_aarch64-10696886.zip
    unzip -d /path/to/android-sdk -n emulator.zip
    rm -f emulator.zip
    cp /path/to/android-sdk/platform-tools/package.xml /path/to/android-sdk/emulator/package.xml
    sed -i \
      -e 's|path="[a-zA-Z-]*"|path="emulator"|g' \
      -e 's|<major>[0-9]*<\/major>|<major>32<\/major>|g' \
      -e 's|<minor>[0-9]*<\/minor>|<minor>1<\/minor>|g' \
      -e 's|<micro>[0-9]*<\/micro>|<micro>15<\/micro>|g' \
      -e 's|<display-name>Android .*<\/display-name>|<display-name>Android Emulator<\/display-name>|g' \
      /path/to/android-sdk/emulator/package.xml
- run: sdkmanager tools

Still fails with below errors, working on that

emulator: cannot execute binary file: Exec format error
adb: cannot execute binary file: Exec format error

Might try

https://ci.android.com/builds/submitted/10696670/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-10696670.zip

Instead of

https://redirector.gvt1.com/edgedl/android/repository/emulator-darwin_aarch64-10696886.zip

Finally got ADB and Emulator to work in arm64/aarch64 without KVM using below step.

- name: Setup Android SDK
  uses: android-actions/setup-android@v3
  with:
    packages: 'platform-tools'

# https://github.com/lzhiyong/android-sdk-tools/releases
- name: Install ADB
  run: |
    curl --compressed --location --output tools.zip https://github.com/lzhiyong/android-sdk-tools/releases/download/34.0.3/android-sdk-tools-static-aarch64.zip
    unzip -d tools -n -q tools.zip
    rm -f tools.zip
    cp tools/platform-tools/adb /path/to/android-sdk/platform-tools/adb
    rm -fr tools
  shell: bash

# https://ci.android.com/builds/branches/aosp-emu-master-dev/grid
- name: Install Emulator
  run: |
    curl --compressed --location --output emulator.zip $(curl --location --silent https://ci.android.com/builds/submitted/11162281/emulator-linux_aarch64/latest/sdk-repo-linux_aarch64-emulator-11162281.zip | grep -o 'https://storage[^"]*' | sed 's/\\u0026/\&/g')
    unzip -d /path/to/android-sdk -n -q emulator.zip
    rm -f emulator.zip
    cp /path/to/android-sdk/platform-tools/package.xml /path/to/android-sdk/emulator/package.xml
    sed -i \
      -e 's|path="[a-zA-Z-]*"|path="emulator"|g' \
      -e 's|<display-name>Android .*<\/display-name>|<display-name>Android Emulator<\/display-name>|g' \
      /path/to/android-sdk/emulator/package.xml
    echo 'Vulkan = off\nGLDirectMem = on' >> ~/.android/advancedFeatures.ini
  shell: bash

- name: Install SDK Tools
  run: |
    sdkmanager 'platforms;android-34' 'system-images;android-34;google_apis;arm64-v8a' 'tools'
    bash -c 'yes || true' | sdkmanager --licenses
  shell: bash

juliusiqbalfn avatar Dec 04 '23 12:12 juliusiqbalfn