Skip to content

Commit 4f18d18

Browse files
feat(rn-upgrade): upgrade to rn 0.70 (#200)
1 parent 3fb9d97 commit 4f18d18

20 files changed

+1243
-1364
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ build/
2929
.gradle
3030
local.properties
3131
*.iml
32+
.cxx/
3233

3334
# Build
3435
lib/

example/android/app/build.gradle

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,12 @@ android {
145145
if (isNewArchitectureEnabled()) {
146146
// We configure the NDK build only if you decide to opt-in for the New Architecture.
147147
externalNativeBuild {
148-
ndkBuild {
149-
arguments "APP_PLATFORM=android-21",
150-
"APP_STL=c++_shared",
151-
"NDK_TOOLCHAIN_VERSION=clang",
152-
"GENERATED_SRC_DIR=$buildDir/generated/source",
153-
"PROJECT_BUILD_DIR=$buildDir",
154-
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
155-
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
156-
"NODE_MODULES_DIR=$rootDir/../node_modules"
157-
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
158-
cppFlags "-std=c++17"
159-
// Make sure this target name is the same you specify inside the
160-
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
161-
targets "geolocationexample_appmodules"
162-
// Fix for windows limit on number of character in file paths and in command lines
163-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
164-
arguments "NDK_APP_SHORT_COMMANDS=true"
165-
}
148+
cmake {
149+
arguments "-DPROJECT_BUILD_DIR=$buildDir",
150+
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
151+
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
152+
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
153+
"-DANDROID_STL=c++_shared"
166154
}
167155
}
168156
if (!enableSeparateBuildPerCPUArchitecture) {
@@ -176,8 +164,8 @@ android {
176164
if (isNewArchitectureEnabled()) {
177165
// We configure the NDK build only if you decide to opt-in for the New Architecture.
178166
externalNativeBuild {
179-
ndkBuild {
180-
path "$projectDir/src/main/jni/Android.mk"
167+
cmake {
168+
path "$projectDir/src/main/jni/CMakeLists.txt"
181169
}
182170
}
183171
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
@@ -199,15 +187,15 @@ android {
199187
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
200188

201189
// Due to a bug inside AGP, we have to explicitly set a dependency
202-
// between configureNdkBuild* tasks and the preBuild tasks.
190+
// between configureCMakeDebug* tasks and the preBuild tasks.
203191
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
204-
configureNdkBuildRelease.dependsOn(preReleaseBuild)
205-
configureNdkBuildDebug.dependsOn(preDebugBuild)
192+
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
193+
configureCMakeDebug.dependsOn(preDebugBuild)
206194
reactNativeArchitectures().each { architecture ->
207-
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
195+
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
208196
dependsOn("preDebugBuild")
209197
}
210-
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
198+
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
211199
dependsOn("preReleaseBuild")
212200
}
213201
}

example/android/app/src/main/jni/Android.mk

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
# Define the library name here.
3+
project(geolocationexample_appmodules)
4+
# This file includes all the necessary to let you build your application with the New Architecture.
5+
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

example/android/app/src/main/jni/MainApplicationModuleProvider.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include "MainApplicationModuleProvider.h"
22

3+
#include <rncli.h>
34
#include <rncore.h>
45
#include <RNCGeolocation.h>
56

67
namespace facebook {
78
namespace react {
89

910
std::shared_ptr<TurboModule> MainApplicationModuleProvider(
10-
const std::string moduleName,
11+
const std::string &moduleName,
1112
const JavaTurboModule::InitParams &params) {
1213
// Here you can provide your own module provider for TurboModules coming from
1314
// either your application or from external libraries. The approach to follow
@@ -18,11 +19,13 @@ std::shared_ptr<TurboModule> MainApplicationModuleProvider(
1819
// return module;
1920
// }
2021
// return rncore_ModuleProvider(moduleName, params);
21-
auto module = RNCGeolocation_ModuleProvider(moduleName, params);
2222

23-
if (module != nullptr) {
24-
return module;
23+
// Module providers autolinked by RN CLI
24+
auto rncli_module = rncli_ModuleProvider(moduleName, params);
25+
if (rncli_module != nullptr) {
26+
return rncli_module;
2527
}
28+
2629
return rncore_ModuleProvider(moduleName, params);
2730
}
2831

example/android/app/src/main/jni/MainApplicationModuleProvider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace facebook {
99
namespace react {
1010

1111
std::shared_ptr<TurboModule> MainApplicationModuleProvider(
12-
const std::string moduleName,
12+
const std::string &moduleName,
1313
const JavaTurboModule::InitParams &params);
1414

1515
} // namespace react

example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@ void MainApplicationTurboModuleManagerDelegate::registerNatives() {
2222

2323
std::shared_ptr<TurboModule>
2424
MainApplicationTurboModuleManagerDelegate::getTurboModule(
25-
const std::string name,
26-
const std::shared_ptr<CallInvoker> jsInvoker) {
25+
const std::string &name,
26+
const std::shared_ptr<CallInvoker> &jsInvoker) {
2727
// Not implemented yet: provide pure-C++ NativeModules here.
2828
return nullptr;
2929
}
3030

3131
std::shared_ptr<TurboModule>
3232
MainApplicationTurboModuleManagerDelegate::getTurboModule(
33-
const std::string name,
33+
const std::string &name,
3434
const JavaTurboModule::InitParams &params) {
3535
return MainApplicationModuleProvider(name, params);
3636
}
3737

38-
bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule(
39-
std::string name) {
38+
bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule(const std::string &name) {
4039
return getTurboModule(name, nullptr) != nullptr ||
4140
getTurboModule(name, {.moduleName = name}) != nullptr;
4241
}

example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ class MainApplicationTurboModuleManagerDelegate
2121
static void registerNatives();
2222

2323
std::shared_ptr<TurboModule> getTurboModule(
24-
const std::string name,
25-
const std::shared_ptr<CallInvoker> jsInvoker) override;
24+
const std::string &name,
25+
const std::shared_ptr<CallInvoker> &jsInvoker) override;
2626
std::shared_ptr<TurboModule> getTurboModule(
27-
const std::string name,
27+
const std::string &name,
2828
const JavaTurboModule::InitParams &params) override;
2929

3030
/**
3131
* Test-only method. Allows user to verify whether a TurboModule can be
3232
* created by instances of this class.
3333
*/
34-
bool canCreateTurboModule(std::string name);
34+
bool canCreateTurboModule(const std::string &name);
3535
};
3636

3737
} // namespace react

example/android/app/src/main/jni/MainComponentsRegistry.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <fbjni/fbjni.h>
55
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
66
#include <react/renderer/components/rncore/ComponentDescriptors.h>
7+
#include <rncli.h>
78

89
namespace facebook {
910
namespace react {
@@ -14,6 +15,9 @@ std::shared_ptr<ComponentDescriptorProviderRegistry const>
1415
MainComponentsRegistry::sharedProviderRegistry() {
1516
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
1617

18+
// Autolinked providers registered by RN CLI
19+
rncli_registerProviders(providerRegistry);
20+
1721
// Custom Fabric Components go here. You can register custom
1822
// components coming from your App or from 3rd party libraries here.
1923
//

example/android/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import org.apache.tools.ant.taskdefs.condition.Os
2-
31
// Top-level build file where you can add configuration options common to all sub-projects/modules.
42

53
buildscript {
@@ -22,7 +20,7 @@ buildscript {
2220
mavenCentral()
2321
}
2422
dependencies {
25-
classpath("com.android.tools.build:gradle:7.1.1")
23+
classpath("com.android.tools.build:gradle:7.2.1")
2624
classpath("com.facebook.react:react-native-gradle-plugin")
2725
classpath("de.undercouch:gradle-download-task:5.0.1")
2826
// NOTE: Do not place your application dependencies here; they belong

0 commit comments

Comments
 (0)