Skip to content

Commit

Permalink
Upgrade react-native 0.70 (expo#19261)
Browse files Browse the repository at this point in the history
# Why

update react-native to 0.70 for sdk 47

# How

- update package versions
  - `react` 18.0.0 -> 18.1.0
  - `react-native` 0.69.5 -> 0.70.1
  - `react-native-web` ~0.18.7 -> ~0.18.9
  - `react-test-renderer` 18.0.0 -> 18.1.0
  - `metro-react-native-babel-preset` ~0.70.3 -> ~0.72.1
  - `react-native-reanimated` 2.9.1 -> 2.10.0 (because 2.9 doesn't support react-native 0.70)
  - [NCL] remove unused react-native-redash
  - [NCL] `@react-navigation/native` ~5.8.9 -> ~5.9.8 (fixed the deprecated Linking.removeEventListener)
- migrate templates based on [rn-upgrade helper](https://react-native-community.github.io/upgrade-helper/?from=0.69.5&to=0.70.1). one exception is that we still use jsc by default in sdk 47.
  - expo-template-bare-minimum
  - bare-expo
  - bare-sandbox
  - fabric-tester
  - native-tests
  - android (expo go)
  - ios (expo go)
- update our react-native fork to 0.70 based 
- [android] use ReactAndroid directly from _react-native-lab/react-native/ReactAndroid_ without copying a lot of files to expo/expo to increase the repo size. close ENG-4562. i will remove _android/ReactAndroid_ and _android/ReactCommon_ in a separate commit.
  - toward this, i also change the prebuiltHermes support in this pr. the target react-native hermes version is in `react-native-lab/react-native/sdks/.hermesversion` and the cached hermes is now in `android/prebuiltHermes/.hermesversion`.
- [tools] update-rn: support running transformer directly in _react-native-lab/react-native_
- [ios] backport folly version to previous versioned code
- [0.70 breaking change] fix skia build error for `jsi::detail::throwJSError`. use `throw jsi::JSError` instead as upstream latest code.
- [0.70 breaking change][updates] `NativeModuleCallExceptionHandler -> JSExceptionHandler`. change from facebook/react-native@b6f7689

# Test Plan

- ✅ android expo go + unversioned NCL
- ✅ ios expo go + unversioned NCL
- ✅ android bare-expo
- ✅ ios bare-expo
- ✅ android fabric-tester
- ✅ ios fabric-tester
- ✅ ci passed
  - android client - eas build is broken on main.  expo#19270 may address the issue.
  - updates e2e is broken on main. the root cause should come from expo#18653 when proguard is enabled, the app will crash. will follow up in separated pr.

Co-authored-by: Tomasz Sapeta <[email protected]>
  • Loading branch information
Kudo and tsapeta authored Sep 28, 2022
1 parent 7aebe42 commit 22b45c5
Show file tree
Hide file tree
Showing 178 changed files with 2,149 additions and 2,170 deletions.
16 changes: 8 additions & 8 deletions .github/actions/expo-caches/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,28 @@ runs:
if: inputs.hermes-engine-aar == 'true'
uses: actions/cache@v2
with:
path: android/ReactAndroid/prebuiltHermes
key: hermes-engine-aar-v2-${{ hashFiles('android/sdks/.hermesversion') }}
path: android/prebuiltHermes
key: hermes-engine-aar-v2-${{ hashFiles('react-native-lab/react-native/sdks/.hermesversion') }}
- name: Check hermes-engine cache-hit
if: inputs.hermes-engine-aar == 'true'
id: cache-hermes-engine-aar
shell: bash
run: |
CURRENT_VERSION=$(test -f android/ReactAndroid/prebuiltHermes/.hermesversion && cat android/ReactAndroid/prebuiltHermes/.hermesversion) || true
TARGET_VERSION=$(test -f android/sdks/.hermesversion && cat android/sdks/.hermesversion) || true
CURRENT_VERSION=$(test -f android/prebuiltHermes/.hermesversion && cat android/prebuiltHermes/.hermesversion) || true
TARGET_VERSION=$(test -f react-native-lab/react-native/sdks/.hermesversion && cat react-native-lab/react-native/sdks/.hermesversion) || true
if [[ $CURRENT_VERSION == $TARGET_VERSION ]]; then echo '::set-output name=cache-hit::true'; else echo '::set-output name=cache-hit::false'; fi
- name: 🛠 Rebuild hermes-engine AAR when cache missed
if: inputs.hermes-engine-aar == 'true' && inputs.rebuild-hermes-engine-aar-if-needed == 'true' && steps.cache-hermes-engine-aar.outputs.cache-hit != 'true'
shell: bash
run: |
# Ensure node packages are installed when yarn-workspace cache miss
yarn install --frozen-lockfile
mkdir -p ReactAndroid/prebuiltHermes
cp -f sdks/.hermesversion ReactAndroid/prebuiltHermes/
mkdir -p prebuiltHermes
cp -f ../react-native-lab/react-native/sdks/.hermesversion prebuiltHermes/
./gradlew :ReactAndroid:hermes-engine:assembleRelease
./gradlew :ReactAndroid:hermes-engine:assembleDebug
cp -f ReactAndroid/hermes-engine/build/outputs/aar/hermes-engine-release.aar ReactAndroid/prebuiltHermes/
cp -f ReactAndroid/hermes-engine/build/outputs/aar/hermes-engine-debug.aar ReactAndroid/prebuiltHermes/
cp -f ../react-native-lab/react-native/ReactAndroid/hermes-engine/build/outputs/aar/hermes-engine-release.aar prebuiltHermes/
cp -f ../react-native-lab/react-native/ReactAndroid/hermes-engine/build/outputs/aar/hermes-engine-debug.aar prebuiltHermes/
env:
# Reset reactNativeArchitectures to build all architectures
ORG_GRADLE_PROJECT_reactNativeArchitectures:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/android-instrumentation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ concurrency:
jobs:
test:
runs-on: macos-11
timeout-minutes: 60
timeout-minutes: 80
env:
ORG_GRADLE_PROJECT_reactNativeArchitectures: x86_64
GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=1024m
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
if: steps.expo-caches.outputs.yarn-workspace-hit != 'true'
run: yarn install --frozen-lockfile
- name: 📱 Run instrumented unit tests
timeout-minutes: 45
timeout-minutes: 60
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/android-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ concurrency:
jobs:
test:
runs-on: ubuntu-20.04
timeout-minutes: 60
timeout-minutes: 80
env:
ORG_GRADLE_PROJECT_reactNativeArchitectures: x86_64
GRADLE_OPTS: -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=1024m
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ xcuserdata
/android/versioned-react-native/codegen
/android/versioned-react-native/sdks
ReactAndroid-temp.aar
/android/ReactAndroid/prebuiltHermes
/android/prebuiltHermes

# Tools
jarjar-rules.txt
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
dbFlowVersion = '4.2.4'
buildToolsVersion = '31.0.0'
kotlinVersion = '1.6.10'
gradlePluginVersion = '7.1.1'
gradlePluginVersion = '7.2.1'
gradleDownloadTaskVersion = '5.0.1'
repositoryUrl = "file:${System.env.HOME}/.m2/repository/"

Expand Down
11 changes: 7 additions & 4 deletions android/expoview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ apply plugin: 'de.undercouch.download'
apply plugin: 'kotlin-kapt'
apply from: new File(rootDir, "versioning_linking.gradle")

def hasHermesEngineDeps = false

// WHEN_VERSIONING_REMOVE_FROM_HERE
//maven repository info
group = 'host.exp.exponent'
Expand Down Expand Up @@ -51,7 +53,7 @@ def reactProperties = new Properties()
def reactNative = new File("$projectDir/../../versioned-react-native")

// WHEN_VERSIONING_REMOVE_FROM_HERE
reactNative = new File("$projectDir/..")
reactNative = new File("$projectDir/../../react-native-lab/react-native")
// WHEN_VERSIONING_REMOVE_TO_HERE

file("$reactNative/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
Expand All @@ -71,9 +73,9 @@ def reactNativeArchitectures() {
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def prebuiltHermesDir = findProperty("expo.prebuiltHermesDir") ?: file("${project(':ReactAndroid').projectDir}/prebuiltHermes")
def prebuiltHermesDir = findProperty("expo.prebuiltHermesDir") ?: file("${rootDir}/prebuiltHermes")
def prebuiltHermesVersion = file("${prebuiltHermesDir}/.hermesversion").exists() ? file("${prebuiltHermesDir}/.hermesversion").text : null
def currentHermesVersion = file("${rootDir}/sdks/.hermesversion").exists() ? file("${rootDir}/sdks/.hermesversion").text : null
def currentHermesVersion = file("${project(':ReactAndroid').projectDir}/../sdks/.hermesversion").exists() ? file("${project(':ReactAndroid').projectDir}/../sdks/.hermesversion").text : null
def buildHermesSource = currentHermesVersion != prebuiltHermesVersion
logger.info(":expoview - buildHermesSource[${buildHermesSource}]")

Expand Down Expand Up @@ -302,6 +304,7 @@ dependencies {
exclude(group:'com.facebook.fbjni', module: 'fbjni')
}
}
hasHermesEngineDeps = true

// Expo modules
api project(':expo')
Expand Down Expand Up @@ -794,7 +797,7 @@ tasks.whenTaskAdded { task ->
}

def hermesAAR = new File("${reactNative}/ReactAndroid/hermes-engine/build/outputs/aar/hermes-engine-release.aar")
if (hermesAAR.exists()) {
if (hermesAAR.exists() && !hasHermesEngineDeps) {
dependencies {
compileOnly(files(hermesAAR))
}
Expand Down
Binary file modified android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
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-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions android/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,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
14 changes: 8 additions & 6 deletions android/gradlew.bat
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,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,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 +75,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
3 changes: 2 additions & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ includeBuild('../react-native-lab/react-native/packages/react-native-gradle-plug
include ':expoview'
include ':tools'
include ':ReactAndroid'
project(':ReactAndroid').projectDir = new File(rootDir, '../react-native-lab/react-native/ReactAndroid')
include ':ReactAndroid:hermes-engine'
project(':ReactAndroid:hermes-engine').projectDir = new File(rootDir, 'ReactAndroid/hermes-engine')
project(':ReactAndroid:hermes-engine').projectDir = new File(rootDir, '../react-native-lab/react-native/ReactAndroid/hermes-engine')
include ':expo-modules-test-core'
project(':expo-modules-test-core').projectDir = new File(rootDir, '../packages/expo-modules-test-core/android')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@

public class ReactAndroidCodeTransformer {

private static final String REACT_COMMON_SOURCE_ROOT = "react-native-lab/react-native/ReactCommon";
private static final String REACT_COMMON_DEST_ROOT = "android/ReactCommon";
private static final String REACT_ANDROID_SOURCE_ROOT = "react-native-lab/react-native/ReactAndroid";
private static final String REACT_ANDROID_DEST_ROOT = "android/ReactAndroid";
private static final String REACT_ANDROID_DEST_ROOT = "react-native-lab/react-native/ReactAndroid";
private static final String SOURCE_PATH = "src/main/java/com/facebook/react/";

private static abstract class MethodVisitor {
Expand Down Expand Up @@ -243,7 +240,7 @@ public Node visit(String methodName, MethodDeclaration n) {
return n;
}
});
FILES_TO_MODIFY.put("bridge/DefaultNativeModuleCallExceptionHandler.java", new MethodVisitor() {
FILES_TO_MODIFY.put("bridge/DefaultJSExceptionHandler.java", new MethodVisitor() {

@Override
public Node visit(String methodName, MethodDeclaration n) {
Expand Down Expand Up @@ -298,19 +295,6 @@ public static void main(final String[] args) throws IOException {
throw new IllegalArgumentException("Invalid args passed in, expected one argument -- SDK version.");
}

// Don't want to mess up our original copy of ReactCommon and ReactAndroid if something goes wrong.
File reactCommonDestRoot = new File(projectRoot + REACT_COMMON_DEST_ROOT);
File reactAndroidDestRoot = new File(projectRoot + REACT_ANDROID_DEST_ROOT);

// Always remove
FileUtils.deleteDirectory(reactCommonDestRoot);
reactCommonDestRoot = new File(projectRoot + REACT_COMMON_DEST_ROOT);
FileUtils.deleteDirectory(reactAndroidDestRoot);
reactAndroidDestRoot = new File(projectRoot + REACT_ANDROID_DEST_ROOT);

FileUtils.copyDirectory(new File(projectRoot + REACT_COMMON_SOURCE_ROOT), reactCommonDestRoot);
FileUtils.copyDirectory(new File(projectRoot + REACT_ANDROID_SOURCE_ROOT), reactAndroidDestRoot);

// Update maven publish information
replaceInFile(new File(projectRoot + REACT_ANDROID_DEST_ROOT + "/build.gradle"),
"def AAR_OUTPUT_URL = \"file://${projectDir}/../android\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def prebuiltDir = sourceBuild


def reactProperties = new Properties()
file("$nodeModules/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
file("$defaultDir/gradle.properties").withInputStream { reactProperties.load(it) }
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()

logger.warn("react-native-skia: React Native version: ${REACT_NATIVE_VERSION}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace RNSkia
{
if (contourMeasure == nullptr)
{
jsi::detail::throwJSError(*context->getJsRuntime(), "Contour measure is null");
throw jsi::JSError(*context->getJsRuntime(), "Contour measure is null");
}
};

Expand All @@ -41,7 +41,7 @@ namespace RNSkia
auto result = getObject()->getPosTan(dist, &position, &tangent);
if (!result)
{
jsi::detail::throwJSError(runtime, "getSegment() failed");
throw jsi::JSError(runtime, "getSegment() failed");
}
auto posTan = jsi::Object(runtime);
posTan.setProperty(runtime, "px", position.x());
Expand Down Expand Up @@ -70,7 +70,7 @@ namespace RNSkia
auto result = getObject()->getSegment(start, end, &path, startWithMoveTo);
if (!result)
{
jsi::detail::throwJSError(runtime, "getSegment() failed");
throw jsi::JSError(runtime, "getSegment() failed");
}
return JsiSkPath::toValue(runtime, getContext(), std::move(path));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ namespace RNSkia {
size_t len;
auto err = SkBase64::Decode(&base64.utf8(runtime).c_str()[0], size, nullptr, &len);
if(err != SkBase64::Error::kNoError) {
jsi::detail::throwJSError(runtime, "Error decoding base64 string");
throw jsi::JSError(runtime, "Error decoding base64 string");
return jsi::Value::undefined();
}

// Create data object and decode
auto data = SkData::MakeUninitialized(len);
err = SkBase64::Decode(&base64.utf8(runtime).c_str()[0], size, data->writable_data(), &len);
if(err != SkBase64::Error::kNoError) {
jsi::detail::throwJSError(runtime, "Error decoding base64 string");
throw jsi::JSError(runtime, "Error decoding base64 string");
return jsi::Value::undefined();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace RNSkia

if (glyphs.size() > positions.size())
{
jsi::detail::throwJSError(runtime, "Not enough x,y position pairs for glyphs");
throw jsi::JSError(runtime, "Not enough x,y position pairs for glyphs");
return jsi::Value::null();
}
auto sects = getObject()->getIntercepts(glyphs.data(), SkToInt(glyphs.size()), positions.data(), top, bottom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class JsiSkPathFactory : public JsiSkHostObject {
SkPath result;

if (!SkParsePath::FromSVGString(svgString.c_str(), &result)) {
jsi::detail::throwJSError(runtime, "Could not parse Svg path");
throw jsi::JSError(runtime, "Could not parse Svg path");
return jsi::Value(nullptr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class JsiSkPictureFactory : public JsiSkHostObject {
public:
JSI_HOST_FUNCTION(MakePicture) {
if(!arguments[0].isObject()) {
jsi::detail::throwJSError(runtime, "Expected arraybuffer as first parameter");
throw jsi::JSError(runtime, "Expected arraybuffer as first parameter");
}
auto array = arguments[0].asObject(runtime);
jsi::ArrayBuffer buffer = array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace RNSkia
{
auto i = static_cast<int>(arguments[0].asNumber());
if (i < 0 || i >= getObject()->uniforms().size()) {
jsi::detail::throwJSError(runtime, "invalid uniform index");
throw jsi::JSError(runtime, "invalid uniform index");
}
auto it = getObject()->uniforms().begin() + i;
return jsi::String::createFromAscii(runtime, it->name.c_str());
Expand All @@ -106,7 +106,7 @@ namespace RNSkia
{
auto i = static_cast<int>(arguments[0].asNumber());
if (i < 0 || i >= getObject()->uniforms().size()) {
jsi::detail::throwJSError(runtime, "invalid uniform index");
throw jsi::JSError(runtime, "invalid uniform index");
}
auto it = getObject()->uniforms().begin() + i;
auto result = jsi::Object(runtime);
Expand Down Expand Up @@ -144,7 +144,7 @@ namespace RNSkia
std::to_string(jsiUniformsSize) +
" expected " +
std::to_string(getObject()->uniformSize() / sizeof(float));
jsi::detail::throwJSError(runtime, msg.c_str());
throw jsi::JSError(runtime, msg.c_str());
}

auto uniforms = SkData::MakeUninitialized(getObject()->uniformSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class JsiSkRuntimeEffectFactory : public JsiSkHostObject {
auto effect = result.effect;
auto errorText = result.errorText;
if (!effect) {
jsi::detail::throwJSError(
throw jsi::JSError(
runtime,
std::string("Error in sksl:\n" + std::string(errorText.c_str()))
.c_str());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ class RNSkJsiViewApi : public JsiHostObject {
image = info->view->makeImageSnapshot(nullptr);
}
if(image == nullptr) {
jsi::detail::throwJSError(runtime, "Could not create image from current surface.");
throw jsi::JSError(runtime, "Could not create image from current surface.");
return jsi::Value::undefined();
}
return jsi::Object::createFromHostObject(runtime, std::make_shared<JsiSkImage>(_platformContext, image));
}
jsi::detail::throwJSError(runtime, "No Skia View currently available.");
throw jsi::JSError(runtime, "No Skia View currently available.");
return jsi::Value::undefined();
}

Expand Down Expand Up @@ -152,7 +152,7 @@ class RNSkJsiViewApi : public JsiHostObject {
JSI_HOST_FUNCTION(registerValuesInView) {
// Check params
if(!arguments[1].isObject() || !arguments[1].asObject(runtime).isArray(runtime)) {
jsi::detail::throwJSError(runtime, "Expected array of Values as second parameter");
throw jsi::JSError(runtime, "Expected array of Values as second parameter");
return jsi::Value::undefined();
}

Expand Down
Loading

0 comments on commit 22b45c5

Please sign in to comment.