diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 53f0d6feb..b2feca0b3 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -1,6 +1,6 @@ name: Build jsc-android and test -on: [push] +on: [push, pull_request] jobs: build: @@ -27,7 +27,6 @@ jobs: - name: Install Android packages run: | sdkmanager \ - "lldb;3.0" \ "cmake;3.10.2.4988404" shell: bash - name: Build @@ -44,7 +43,7 @@ jobs: mv dist.unstripped archive/ shell: bash - - uses: actions/upload-artifact@master + - uses: actions/upload-artifact@v2 with: name: archive path: archive @@ -57,33 +56,15 @@ jobs: steps: - uses: actions/checkout@v1 - - uses: actions/download-artifact@master + - uses: actions/download-artifact@v2 with: name: archive path: archive - - name: Launch AVD - run: | - source scripts/android-setup.sh - export PATH="${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}" - export AVD_PACKAGES="system-images;android-${ANDROID_SDK_TARGET_API_LEVEL};google_apis;${AVD_ABI}" - sdkmanager "${AVD_PACKAGES}" - createAVD - launchAVD & - shell: bash - - - name: Wait AVD - run: | - export PATH="${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}" - source scripts/android-setup.sh - set +e +o pipefail - waitForAVD - shell: bash - - name: Run test - run: | - mv archive/dist . - cd test - yarn - cd android && ./gradlew assembleDebug assembleAndroidTest connectedAndroidTest - shell: bash + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 16 + arch: x86 + disable-animations: false + script: mv archive/dist . && cd test && yarn && cd android && ./gradlew assembleRelease assembleAndroidTest connectedAndroidTest diff --git a/scripts/.tests.env b/scripts/.tests.env deleted file mode 100644 index e1f16c7e1..000000000 --- a/scripts/.tests.env +++ /dev/null @@ -1,30 +0,0 @@ -# These should match the recommended versions listed in -# https://facebook.github.io/react-native/docs/getting-started.html - - -## ANDROID ## -# Android SDK Build Tools revision -export ANDROID_SDK_BUILD_TOOLS_REVISION=28.0.3 -# Android API Level we build with -export ANDROID_SDK_BUILD_API_LEVEL="28" -# Google APIs for Android level -export ANDROID_GOOGLE_API_LEVEL="23" -# Minimum Android API Level we target -export ANDROID_SDK_TARGET_API_LEVEL="16" -# Android Virtual Device name -export AVD_NAME="testAVD" -# ABI to use in Android Virtual Device -export AVD_ABI=x86 - -## IOS ## -export IOS_TARGET_OS="12.4" -export IOS_DEVICE="iPhone 6s" -export TVOS_DEVICE="Apple TV" - -## CI OVERRIDES ## -# Values to override when running in CI -# $CI is set by Circle CI -if [ $CI ]; then - # Use ARM on Circle CI - export AVD_ABI=armeabi-v7a -fi diff --git a/scripts/android-setup.sh b/scripts/android-setup.sh deleted file mode 100755 index a0e0a0335..000000000 --- a/scripts/android-setup.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash -# Copyright (c) Facebook, Inc. and its affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# inspired by https://github.com/Originate/guide/blob/master/android/guide/Continuous%20Integration.md - -# shellcheck disable=SC1091 -source "scripts/.tests.env" - -function getAndroidPackages { - export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools.bin:$PATH" - - DEPS="$ANDROID_HOME/installed-dependencies" - - # Package names can be obtained using `sdkmanager --list` - if [ ! -e "$DEPS" ] || [ ! "$CI" ]; then - echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, $AVD_ABI system image..." - sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI" - echo "Installing build SDK for Android API level $ANDROID_SDK_BUILD_API_LEVEL..." - sdkmanager "platforms;android-$ANDROID_SDK_BUILD_API_LEVEL" - echo "Installing target SDK for Android API level $ANDROID_SDK_TARGET_API_LEVEL..." - sdkmanager "platforms;android-$ANDROID_SDK_TARGET_API_LEVEL" - echo "Installing SDK build tools, revision $ANDROID_SDK_BUILD_TOOLS_REVISION..." - sdkmanager "build-tools;$ANDROID_SDK_BUILD_TOOLS_REVISION" - # These moved to "system-images;android-$ANDROID_SDK_BUILD_API_LEVEL;google_apis;x86" starting with API level 25, but there is no ARM version. - echo "Installing Google APIs $ANDROID_GOOGLE_API_LEVEL..." - sdkmanager "add-ons;addon-google_apis-google-$ANDROID_GOOGLE_API_LEVEL" - echo "Installing Android Support Repository" - sdkmanager "extras;android;m2repository" - $CI && touch "$DEPS" - fi -} - -function getAndroidNDK { - NDK_HOME="/opt/ndk" - DEPS="$NDK_HOME/installed-dependencies" - - if [ ! -e $DEPS ]; then - cd $NDK_HOME || exit - echo "Downloading NDK..." - curl -o ndk.zip https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip - unzip -o -q ndk.zip - echo "Installed Android NDK at $NDK_HOME" - touch $DEPS - rm ndk.zip - fi -} - -function createAVD { - AVD_PACKAGES="system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI" - echo "Creating AVD with packages $AVD_PACKAGES" - echo no | avdmanager create avd --name "$AVD_NAME" --force --package "$AVD_PACKAGES" --tag google_apis --abi "$AVD_ABI" -} - -function launchAVD { - # The AVD name here should match the one created in createAVD - if [ "$CI" ] - then - "$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" -no-audio -no-window - else - "$ANDROID_HOME/emulator/emulator" -avd "$AVD_NAME" - fi -} - -function waitForAVD { - echo "Waiting for Android Virtual Device to finish booting..." - local bootanim="" - export PATH=$(dirname $(dirname $(command -v android)))/platform-tools:$PATH - until [[ "$bootanim" =~ "stopped" ]]; do - sleep 5 - bootanim=$(adb -e shell getprop init.svc.bootanim 2>&1) - echo "boot animation status=$bootanim" - done - echo "Android Virtual Device is ready." -} - -function retry3 { - local n=1 - local max=3 - local delay=1 - while true; do - "$@" && break || { - if [[ $n -lt $max ]]; then - ((n++)) - echo "Command failed. Attempt $n/$max:" - sleep $delay; - else - echo "The command has failed after $n attempts." >&2 - return 1 - fi - } - done -} diff --git a/test/android/app/build.gradle b/test/android/app/build.gradle index 0e0078cc9..9bc247c31 100644 --- a/test/android/app/build.gradle +++ b/test/android/app/build.gradle @@ -164,6 +164,9 @@ android { proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" } } + + testBuildType 'release' + // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> @@ -192,10 +195,10 @@ dependencies { implementation jscFlavor } - androidTestImplementation 'androidx.test:core:1.1.0'; - androidTestImplementation 'androidx.test.ext:junit:1.1.0'; - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' - androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'; + androidTestImplementation 'androidx.test:core:1.3.0'; + androidTestImplementation 'androidx.test.ext:junit:1.1.2'; + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test.espresso:espresso-intents:3.3.0'; } // Run this once to be able to run the application with BUCK diff --git a/test/android/app/src/androidTest/java/com/test/SimpleTest.java b/test/android/app/src/androidTest/java/com/test/SimpleTest.java index e6a4e2ad4..3229a3712 100644 --- a/test/android/app/src/androidTest/java/com/test/SimpleTest.java +++ b/test/android/app/src/androidTest/java/com/test/SimpleTest.java @@ -7,13 +7,13 @@ import android.view.View; -import androidx.test.core.app.ActivityScenario; import androidx.test.espresso.ViewAction; import androidx.test.espresso.UiController; import androidx.test.espresso.PerformException; import androidx.test.espresso.util.TreeIterables; import androidx.test.espresso.util.HumanReadables; import androidx.test.filters.LargeTest; +import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import java.util.concurrent.TimeoutException; @@ -29,10 +29,8 @@ @LargeTest public class SimpleTest { - @Before - public void launchActivity() { - ActivityScenario.launch(MainActivity.class); - } + @Rule public ActivityScenarioRule activityScenarioRule + = new ActivityScenarioRule<>(MainActivity.class); @Test public void testIfAppLoads() {