Skip to content

Commit

Permalink
[Mobile] - React Native 0.69.4 Upgrade - Android (#43486)
Browse files Browse the repository at this point in the history
* Mobile - React Native 0.69.4 upgrade, base Android changes

* Mobile - Remove RNGestureHandlerEnabledRootView since its now deprecated

* Mobile - Update bundle android script
  • Loading branch information
Gerardo Pacheco committed Oct 19, 2022
1 parent edea9ae commit da1bfca
Show file tree
Hide file tree
Showing 25 changed files with 688 additions and 39 deletions.
25 changes: 14 additions & 11 deletions packages/edit-post/src/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import memize from 'memize';
import { map } from 'lodash';
import { I18nManager } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';

/**
* WordPress dependencies
Expand Down Expand Up @@ -173,17 +174,19 @@ class Editor extends Component {
};

return (
<SlotFillProvider>
<EditorProvider
settings={ editorSettings }
post={ normalizedPost }
initialEdits={ initialEdits }
useSubRegistry={ false }
{ ...props }
>
<Layout setTitleRef={ this.setTitleRef } />
</EditorProvider>
</SlotFillProvider>
<GestureHandlerRootView style={ { flex: 1 } }>
<SlotFillProvider>
<EditorProvider
settings={ editorSettings }
post={ normalizedPost }
initialEdits={ initialEdits }
useSubRegistry={ false }
{ ...props }
>
<Layout setTitleRef={ this.setTitleRef } />
</EditorProvider>
</SlotFillProvider>
</GestureHandlerRootView>
);
}
}
Expand Down
9 changes: 7 additions & 2 deletions packages/react-native-aztec/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,15 @@ repositories {
includeGroup "org.wordpress.aztec"
}
}
maven { url "https://a8c-libs.s3.amazonaws.com/android/hermes-mirror" }
maven { url "https://a8c-libs.s3.amazonaws.com/android/react-native-mirror" }
google()
mavenCentral()
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup "com.facebook.react"
}
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ android {

repositories {
maven { url "https://a8c-libs.s3.amazonaws.com/android" }
maven { url "https://a8c-libs.s3.amazonaws.com/android/hermes-mirror" }
maven { url "https://jitpack.io" }
google()
mavenCentral()
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup "com.facebook.react"
}
}
}

dependencies {
Expand Down Expand Up @@ -83,7 +88,9 @@ dependencies {
exclude group: 'com.github.wordpress-mobile', module: 'react-native-reanimated'
})

runtimeOnly "org.wordpress-mobile:hermes-release-mirror:$rnVersion"
runtimeOnly("com.facebook.react:hermes-engine:$rnVersion", {
exclude group:'com.facebook.fbjni'
})

if (willPublishReactNativeBridgeBinary) {
implementation "org.wordpress-mobile.gutenberg-mobile:react-native-aztec:$reactNativeAztecVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import com.reactnativecommunity.slider.ReactSliderPackage;
import org.linusu.RNGetRandomValuesPackage;
import com.reactnativecommunity.webview.RNCWebViewPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import com.swmansion.gesturehandler.RNGestureHandlerPackage;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
import com.swmansion.reanimated.ReanimatedPackage;
Expand Down Expand Up @@ -615,7 +614,7 @@ public void onCreateView(Context initContext,
mIsDarkMode = gutenbergProps.isDarkMode();
mExceptionLogger = exceptionLogger;
mBreadcrumbLogger = breadcrumbLogger;
mReactRootView = new RNGestureHandlerEnabledRootView(new MutableContextWrapper(initContext));
mReactRootView = new ReactRootView(new MutableContextWrapper(initContext));
mReactRootView.setBackgroundColor(colorBackground);

ReactInstanceManagerBuilder builder =
Expand Down
109 changes: 102 additions & 7 deletions packages/react-native-editor/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ def enableProguardInReleaseBuilds = false
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* This should be set on project.ext.react and that value will be read here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);

/**
* Architectures to build native code for in debug.
* Architectures to build native code for.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
ndkVersion rootProject.ext.ndkVersion
Expand All @@ -130,17 +133,81 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86", "mips"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

if (isNewArchitectureEnabled()) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-21",
"APP_STL=c++_shared",
"NDK_TOOLCHAIN_VERSION=clang",
"GENERATED_SRC_DIR=$buildDir/generated/source",
"PROJECT_BUILD_DIR=$buildDir",
"REACT_ANDROID_DIR=../../../../node_modules/react-native/ReactAndroid",
"REACT_ANDROID_BUILD_DIR=../../../../node_modules/react-native/ReactAndroid/build",
"NODE_MODULES_DIR=../../../../node_modules"
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
cppFlags "-std=c++17"
// Make sure this target name is the same you specify inside the
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
targets "gutenberg_appmodules"
}
}
if (!enableSeparateBuildPerCPUArchitecture) {
ndk {
abiFilters (*reactNativeArchitectures())
}
}
}
}

if (isNewArchitectureEnabled()) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
ndkBuild {
path "$projectDir/src/main/jni/Android.mk"
}
}
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
into("$buildDir/react-ndk/exported")
}
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
into("$buildDir/react-ndk/exported")
}
afterEvaluate {
// If you wish to add a custom TurboModule or component locally,
// you should uncomment this line.
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)

// Due to a bug inside AGP, we have to explicitly set a dependency
// between configureNdkBuild* tasks and the preBuild tasks.
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
configureNdkBuildRelease.dependsOn(preReleaseBuild)
configureNdkBuildDebug.dependsOn(preDebugBuild)
reactNativeArchitectures().each { architecture ->
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
dependsOn("preDebugBuild")
}
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
dependsOn("preReleaseBuild")
}
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
include (*reactNativeArchitectures())
}
}
buildTypes {
Expand Down Expand Up @@ -177,7 +244,7 @@ dependencies {
})
implementation 'androidx.appcompat:appcompat:1.2.0'
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:${extractPackageVersion(packageJson, 'react-native', 'dependencies')}" // From node_modules
implementation "com.facebook.react:react-native:${extractPackageVersion(packageJson, 'react-native', 'dependencies')}"

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

Expand All @@ -199,6 +266,26 @@ dependencies {
// Remove Reanimated transitive dependency as it's already defined here
exclude group: 'com.github.wordpress-mobile', module: 'react-native-reanimated'
})

implementation("com.facebook.react:hermes-engine:${extractPackageVersion(packageJson, 'react-native', 'dependencies')}") {
exclude group:'com.facebook.fbjni'
}
}

if (isNewArchitectureEnabled()) {
// If new architecture is enabled, we let you build RN from source
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
// This will be applied to all the imported transtitive dependency.
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("com.facebook.react:react-native"))
.using(project(":ReactAndroid"))
.because("On New Architecture we're building React Native from source")
substitute(module("com.facebook.react:hermes-engine"))
.using(project(":ReactAndroid:hermes-engine"))
.because("On New Architecture we're building Hermes from source")
}
}
}

// Run this once to be able to run the application with BUCK
Expand All @@ -207,3 +294,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
from configurations.implementation
into 'libs'
}

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
android:networkSecurityConfig="@xml/react_native_config"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

import org.wordpress.mobile.WPAndroidGlue.GutenbergProps;

Expand All @@ -27,11 +25,6 @@ protected String getMainComponentName() {
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}

@Nullable
@Override
protected Bundle getLaunchOptions() {
Expand Down
Loading

0 comments on commit da1bfca

Please sign in to comment.