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

Backport Android API 19 support #291

Open
wants to merge 5 commits into
base: mobile-master
Choose a base branch
from

Conversation

Informatic
Copy link

@Informatic Informatic commented Nov 17, 2020

This monstrosity of a patchset reverts a bunch of libuv changes that dropped Android API 19 support in latest rebase. I am not sure how tight nodejs dependency on specific libuv version is, so maybe libuv version downgrade could somehow solve this in a more graceful manner.

On the other hand, API 19 is pretty much a dead platform nowadays, but since I've already committed into this (like I already did for nodejs-mobile 0.3.1, when patches only involved two files, but I forgot to test it and open a PR), let me just leave that here up for review.

So far I've only tested this on API 25 device (running aarch64, but with ndk.abiFilter set to just armeabi-v7a) and API 19 emulator and it seems to work. I'll try to test it on my proper API 19 target this week. I did some preliminary testing on my target physical platform and it seems to work fine so far. I'll undraft this PR after further testing. I've been using this in production on a bunch of API versions for a couple of months and didn't encounter any issues.

Checklist

@warren-bank
Copy link

warren-bank commented Feb 3, 2021

observation:

  1. android_build.sh
    • foreach (TARGET_ARCH in ['arm', 'x86', 'arm64', 'x86_64']) BUILD_ARCH()
  2. android_build.sh
    • BUILD_ARCH() passes $TARGET_ARCH as a 2nd parameter to android-configure
    • BUILD_ARCH() does not pass any $TARGET_API as a 3rd parameter
  3. android-configure
    • TARGET_API is initialized from 3rd parameter and defaults to 21 when none is passed
suggestion for update to "android_build.sh"
  #!/bin/bash

  set -e

  ROOT=${PWD}

  if [ $# -eq 0 ]
  then
    echo "Requires a path to the Android NDK"
    echo "Usage: android_build.sh <path_to_ndk> [target_arch] [target_api]"
    exit
  fi

  SCRIPT_DIR="$(dirname "$BASH_SOURCE")"
  cd "$SCRIPT_DIR"
  SCRIPT_DIR=${PWD}

  cd "$ROOT"
  cd "$1"
  ANDROID_NDK_PATH=${PWD}
  cd "$SCRIPT_DIR"
  cd ../

  BUILD_ARCH() {
    TARGET_ARCH="$1"
    TARGET_API="$2"

    make clean
    # Clean previous toolchain.
    rm -rf android-toolchain/
    source ./android-configure "$ANDROID_NDK_PATH" "$TARGET_ARCH" "$TARGET_API"
    make -j $(getconf _NPROCESSORS_ONLN)
    TARGET_ARCH_FOLDER="$TARGET_ARCH"
    if [ "$TARGET_ARCH_FOLDER" == "arm" ]; then
      # Use the Android NDK ABI name.
      TARGET_ARCH_FOLDER="armeabi-v7a"
    elif [ "$TARGET_ARCH_FOLDER" == "arm64" ]; then
      # Use the Android NDK ABI name.
      TARGET_ARCH_FOLDER="arm64-v8a"
    fi
    mkdir -p "out_android/$TARGET_ARCH_FOLDER/"
    cp "out/Release/lib.target/libnode.so" "out_android/$TARGET_ARCH_FOLDER/libnode.so"
  }

  # Usage: android_build.sh <path_to_ndk> [target_arch] [target_api]

  # https://developer.android.com/ndk/guides/standalone_toolchain
  # The minimum API level supported by NDK toolchains is currently 16 for 32-bit architectures, and 21 for 64-bit architectures.
  MIN_TARGET_API_32bit='19'
  MIN_TARGET_API_64bit='21'

  if [ $# -eq 3 ]; then
    BUILD_ARCH "$2" "$3"
  elif [ $# -eq 2 ]; then
    PARAM="$2"
    if [ ! -z "${PARAM##*[!0-9]*}" ]; then
      # 2nd param is API (integer)
      if [ "$PARAM" -ge "$MIN_TARGET_API_32bit" ]; then
        BUILD_ARCH "arm" "$PARAM"
        BUILD_ARCH "x86" "$PARAM"
      else
        BUILD_ARCH "arm" "$MIN_TARGET_API_32bit"
        BUILD_ARCH "x86" "$MIN_TARGET_API_32bit"
      fi
      if [ "$PARAM" -ge "$MIN_TARGET_API_64bit" ]; then
        BUILD_ARCH "arm64"  "$PARAM"
        BUILD_ARCH "x86_64" "$PARAM"
      else
        BUILD_ARCH "arm64"  "$MIN_TARGET_API_64bit"
        BUILD_ARCH "x86_64" "$MIN_TARGET_API_64bit"
      fi
    else
      # 2nd param is ARCH
      if [ "arm" == "$PARAM" -o "x86" == "$PARAM" ]; then
        BUILD_ARCH "$PARAM" "$MIN_TARGET_API_32bit"
      else
        BUILD_ARCH "$PARAM" "$MIN_TARGET_API_64bit"
      fi
    fi
  else
    BUILD_ARCH "arm"    "$MIN_TARGET_API_32bit"
    BUILD_ARCH "x86"    "$MIN_TARGET_API_32bit"
    BUILD_ARCH "arm64"  "$MIN_TARGET_API_64bit"
    BUILD_ARCH "x86_64" "$MIN_TARGET_API_64bit"
  fi

  cd "$ROOT"

@Informatic Informatic marked this pull request as ready for review February 3, 2021 22:50
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.

2 participants