Skip to content

Commit

Permalink
Update unit tests and fixtures
Browse files Browse the repository at this point in the history
test
  • Loading branch information
rthic23 committed Jun 13, 2024
1 parent 7417137 commit 56915d5
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 41 deletions.
6 changes: 5 additions & 1 deletion ern-core/src/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function resolveAndroidVersions({
supportLibraryVersion = DEFAULT_SUPPORT_LIBRARY_VERSION,
targetCompatibility = DEFAULT_TARGET_COMPATIBILITY,
targetSdkVersion = DEFAULT_TARGET_SDK_VERSION,
reactNativeGradlePlugin = DEFAULT_RN_GRADLE_PLUGIN_VERSION,
reactNativeGradlePlugin,
reactNativeVersion,
}: {
androidGradlePlugin?: string;
Expand All @@ -88,6 +88,10 @@ export function resolveAndroidVersions({
: DEFAULT_MIN_SDK_VERSION_PRE_RN64;

reactNativeAarVersion = reactNativeAarVersion ?? reactNativeVersion!;
reactNativeGradlePlugin =
reactNativeGradlePlugin ?? semver.lt(reactNativeVersion!, '0.72.0')
? reactNativeGradlePlugin!
: DEFAULT_RN_GRADLE_PLUGIN_VERSION;

return {
androidGradlePlugin,
Expand Down
33 changes: 31 additions & 2 deletions ern-core/test/android-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,29 @@ describe('android.js', () => {
});

describe('resolveAndroidVersions', () => {
it('should return all default versions if no versions are provided [>= RN 0.72.0]', () => {
const versions = android.resolveAndroidVersions({
reactNativeVersion: '0.72.0',
});
expect(versions).deep.equal({
androidGradlePlugin: android.DEFAULT_ANDROID_GRADLE_PLUGIN_VERSION,
androidxAppcompactVersion: android.DEFAULT_ANDROIDX_APPCOMPACT_VERSION,
androidxLifecycleExtrnsionsVersion:
android.DEFAULT_ANDROIDX_LIFECYCLE_EXTENSIONS_VERSION,
buildToolsVersion: android.DEFAULT_BUILD_TOOLS_VERSION,
compileSdkVersion: android.DEFAULT_COMPILE_SDK_VERSION,
gradleDistributionVersion: android.DEFAULT_GRADLE_DISTRIBUTION_VERSION,
kotlinVersion: android.DEFAULT_KOTLIN_VERSION,
minSdkVersion: android.DEFAULT_MIN_SDK_VERSION_POST_RN64,
reactNativeAarVersion: '0.72.0',
reactNativeGradlePlugin: '0.72.11',
sourceCompatibility: android.DEFAULT_SOURCE_COMPATIBILITY,
supportLibraryVersion: android.DEFAULT_SUPPORT_LIBRARY_VERSION,
targetCompatibility: android.DEFAULT_TARGET_COMPATIBILITY,
targetSdkVersion: android.DEFAULT_TARGET_SDK_VERSION,
});
});

it('should return all default versions if no versions are provided [>= RN 0.64.0]', () => {
const versions = android.resolveAndroidVersions({
reactNativeVersion: '0.64.0',
Expand All @@ -224,6 +247,7 @@ describe('android.js', () => {
kotlinVersion: android.DEFAULT_KOTLIN_VERSION,
minSdkVersion: android.DEFAULT_MIN_SDK_VERSION_POST_RN64,
reactNativeAarVersion: '0.64.0',
reactNativeGradlePlugin: undefined,
sourceCompatibility: android.DEFAULT_SOURCE_COMPATIBILITY,
supportLibraryVersion: android.DEFAULT_SUPPORT_LIBRARY_VERSION,
targetCompatibility: android.DEFAULT_TARGET_COMPATIBILITY,
Expand All @@ -245,6 +269,7 @@ describe('android.js', () => {
gradleDistributionVersion: android.DEFAULT_GRADLE_DISTRIBUTION_VERSION,
kotlinVersion: android.DEFAULT_KOTLIN_VERSION,
minSdkVersion: android.DEFAULT_MIN_SDK_VERSION_PRE_RN64,
reactNativeGradlePlugin: undefined,
reactNativeAarVersion: '0.63.0',
sourceCompatibility: android.DEFAULT_SOURCE_COMPATIBILITY,
supportLibraryVersion: android.DEFAULT_SUPPORT_LIBRARY_VERSION,
Expand All @@ -260,6 +285,7 @@ describe('android.js', () => {
minSdkVersion: '15',
sourceCompatibility: 'VERSION_1_9',
targetCompatibility: 'VERSION_1_9',
reactNativeVersion: '0.72.0',
});
expect(versions).deep.equal({
androidGradlePlugin: '3.0.0',
Expand All @@ -271,7 +297,8 @@ describe('android.js', () => {
gradleDistributionVersion: android.DEFAULT_GRADLE_DISTRIBUTION_VERSION,
kotlinVersion: '1.4.0',
minSdkVersion: '15',
reactNativeAarVersion: undefined,
reactNativeAarVersion: '0.72.0',
reactNativeGradlePlugin: '0.72.11',
sourceCompatibility: 'VERSION_1_9',
supportLibraryVersion: android.DEFAULT_SUPPORT_LIBRARY_VERSION,
targetCompatibility: 'VERSION_1_9',
Expand All @@ -293,6 +320,7 @@ describe('android.js', () => {
supportLibraryVersion: '27.0.0',
targetCompatibility: 'VERSION_1_9',
targetSdkVersion: '27',
reactNativeVersion: '0.63.0',
});
expect(versions).deep.equal({
androidGradlePlugin: '3.0.0',
Expand All @@ -303,7 +331,8 @@ describe('android.js', () => {
gradleDistributionVersion: '4.5',
kotlinVersion: '1.4.0',
minSdkVersion: '15',
reactNativeAarVersion: undefined,
reactNativeAarVersion: '0.63.0',
reactNativeGradlePlugin: undefined,
sourceCompatibility: 'VERSION_1_9',
supportLibraryVersion: '27.0.0',
targetCompatibility: 'VERSION_1_9',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
apply plugin: 'com.android.application'
apply plugin: "com.facebook.react"

/**
* The preferred build flavor of JavaScriptCore (JSC)
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'

android {
compileSdkVersion 31
buildToolsVersion "31.0.0"
compileSdkVersion 33
buildToolsVersion "33.0.0"
defaultConfig {
applicationId "com.walmartlabs.ern.dummy"
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
Expand All @@ -17,8 +31,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
// Need this to avoid build conflict with jsr version which comes with react-native
configurations.all {
Expand All @@ -28,15 +42,14 @@ android {
lintOptions {
disable 'InvalidPackage'
}
packagingOptions {
pickFirst "lib/armeabi-v7a/libc++_shared.so"
pickFirst "lib/arm64-v8a/libc++_shared.so"
pickFirst "lib/x86/libc++_shared.so"
pickFirst "lib/x86_64/libc++_shared.so"
}
}

dependencies {
// Recompile this dependency on every build as it can be updated at any time (snapshot)
implementation('com.walmartlabs.ern:runner-ern-container-dummy:1.0.0') { changing = true }
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" android:exported="false"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.facebook.react:react-native-gradle-plugin:'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand All @@ -22,3 +23,22 @@ org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.182.0

# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
# ./gradlew <task> -PreactNativeArchitectures=x86_64
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64

# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 14 additions & 4 deletions ern-runner-gen-android/test/fixtures/simple-android-runner/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -205,6 +209,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
Loading

0 comments on commit 56915d5

Please sign in to comment.