CircleCI-Public / cimg-android

The CircleCI Android Docker Convenience Image.
MIT License
72 stars 37 forks source link

React Native Android builds fail with new Android convenience images #46

Closed PunainenAurinko closed 2 years ago

PunainenAurinko commented 2 years ago

I have been previously using circleci/android:api-30-node image for my React Native Android builds. But I've been getting a warning on CircleCi that I'm using deprecated docker images. So, I decided to upgrade to the new Android cimg convenience images, but my builds now keep failing. I tried cimg/android:2022.03.1, cimg/android:2022.03.1-node, and even cimg/android:2022.03.1-ndk.

Here's the error I'm getting when trying to download Android dependencies on cimg/android:2022.03.1 and cimg/android:2022.03.1-ndk:

#!/bin/bash -eo pipefail
./gradlew androidDependencies
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
:ReactNative:Running '[node, -e, console.log(require('react-native/cli').bin);]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script '/home/circleci/project/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 197

* What went wrong:
A problem occurred evaluating script.
> Cannot run program "node" (in directory "/home/circleci/project/android"): error=2, No such file or directory

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

Exited with code exit status 1
CircleCI received exit code 1

And the builds won't event start when using cimg/android:2022.03.1-node, which I think is the one that I actually should be using, as I was using the node-prefixed image before. This is the error that I'm getting during checkout code step (on the 5th second of the build running):

#!/bin/sh
set -e
# Workaround old docker images with incorrect $HOME
# check https://github.com/docker/docker/issues/2968 for details
if [ "${HOME}" = "/" ]
then
  export HOME=$(getent passwd $(id -un) | cut -d: -f6)
fi

echo "Using SSH Config Dir '$SSH_CONFIG_DIR'"
git --version 

mkdir -p "$SSH_CONFIG_DIR"
chmod 0700 "$SSH_CONFIG_DIR"

printf "%s" 'github.com ssh-rsa <ssh-rsa removed here>
' >> "$SSH_CONFIG_DIR/known_hosts"
chmod 0600 "$SSH_CONFIG_DIR/known_hosts"

rm -f "$SSH_CONFIG_DIR/id_rsa"
printf "%s" "$CHECKOUT_KEY" > "$SSH_CONFIG_DIR/id_rsa"
chmod 0600 "$SSH_CONFIG_DIR/id_rsa"
if (: "${CHECKOUT_KEY_PUBLIC?}") 2>/dev/null; then
  rm -f "$SSH_CONFIG_DIR/id_rsa.pub"
  printf "%s" "$CHECKOUT_KEY_PUBLIC" > "$SSH_CONFIG_DIR/id_rsa.pub"
fi

export GIT_SSH_COMMAND='ssh -i "$SSH_CONFIG_DIR/id_rsa" -o UserKnownHostsFile="$SSH_CONFIG_DIR/known_hosts"'

# use git+ssh instead of https
git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true
git config --global gc.auto 0 || true

if [ -e '/home/circleci/project/.git' ] ; then
  echo 'Fetching into existing repository'
  existing_repo='true'
  cd '/home/circleci/project'
  git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
else
  echo 'Cloning git repository'
  existing_repo='false'
  mkdir -p '/home/circleci/project'
  cd '/home/circleci/project'
  git clone --no-checkout "$CIRCLE_REPOSITORY_URL" .
fi

if [ "$existing_repo" = 'true' ] || [ 'false' = 'true' ]; then
  echo 'Fetching from remote repository'
  if [ -n "$CIRCLE_TAG" ]; then
    git fetch --force --tags origin
  else
    git fetch --force origin +refs/heads/main:refs/remotes/origin/main
  fi
fi

if [ -n "$CIRCLE_TAG" ]; then
  echo 'Checking out tag'
  git checkout --force "$CIRCLE_TAG"
  git reset --hard "$CIRCLE_SHA1"
else
  echo 'Checking out branch'
  git checkout --force -B "$CIRCLE_BRANCH" "$CIRCLE_SHA1"
  git --no-pager log --no-color -n 1 --format='HEAD is now at %h %s'
fi

Using SSH Config Dir '/home/circleci/.ssh'
git version 2.34.1
Cloning git repository
Cloning into '.'...
kex_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

exit status 128
CircleCI received exit code 128

All builds that are run using the deprecated circleci/android:api-30-node go through without any issues.

I need help with this, as I am afraid the deprecated images will be discontinued, and I wont' be able to run my builds. Thank you!

JalexChen commented 2 years ago

hi @PunainenAurinko, could you please provide a link to the builds you are referencing here?

PunainenAurinko commented 2 years ago

@JalexChen Here:

  1. https://app.circleci.com/pipelines/github/pslightningbolt/lightningbolt-mobile/2426/workflows/4759ecaf-86d2-45ed-9724-00b0f01f33a7/jobs/4630
  2. https://app.circleci.com/pipelines/github/pslightningbolt/lightningbolt-mobile/2427/workflows/1b3b2f01-1f00-41bc-b817-7f1b4e69599d/jobs/4634
  3. https://app.circleci.com/pipelines/github/pslightningbolt/lightningbolt-mobile/2428/workflows/0735e5d4-e328-4582-aacd-163dc18069ab/jobs/4637

Thank you!

PunainenAurinko commented 2 years ago

@JalexChen Are there any news on this? I'm not sure if the links are helpful. These are private repos and private workflows.

JalexChen commented 2 years ago

hi @PunainenAurinko - you are correct that the basic 2022.03.1 tag should not be what is used if you have node running. you should use the image with the -node suffix; if you would like to use the -ndk variant (or even the base version), using the node orb to install it onto the container might also be an option if the -node variant continues to not pass the checkout step

Unfortunately, I'm not entirely sure why the build is failing to execute when using the -node variant. As it stands, it looks like it might be a connection issue on your end, which is odd considering the other images are passing that step. Have you since tried running this again and has it at least gotten past that step so we have a bit more to work with?

PunainenAurinko commented 2 years ago

@JalexChen Hey there, I just tried the new April image and it worked for me right away. I am now using cimg/android:2022.04-node for my React Native Android builds and it works perfectly. I didn't need to modify the config at all to use it, I just swapped it with the legacy image and the build went through. I don't know what was wrong with the March Android -node image, but the April one works without issues. Thanks for looking into this though, and you can close this issue now. Thank you!