Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMakeLists.txt and V8Inspector for React Native 0.73 compatibility #195

Merged
merged 6 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,59 @@ $ yarn add react-native-v8 v8-android-jit
@Override
```

For React Native 0.73 and above, you can use the following code instead:

```diff
--- a/android/app/src/main/java/com/rn073/MainApplication.kt
+++ b/android/app/src/main/java/com/rn073/MainApplication.kt
@@ -1,15 +1,20 @@
package com.rn073;

import android.app.Application
+
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
+import com.facebook.react.bridge.JavaScriptExecutorFactory
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
+import com.facebook.react.modules.systeminfo.AndroidInfoHelpers
import com.facebook.soloader.SoLoader

+import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;
+
class MainApplication : Application(), ReactApplication {

override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be auto linked yet can be added manually here, for example:
// add(MyReactNativePackage())
}
override fun getJSMainModuleName(): String = "index"

override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
+
+ override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory =
+ V8ExecutorFactory(
+ applicationContext,
+ packageName,
+ AndroidInfoHelpers.getFriendlyDeviceName(),
+ useDeveloperSupport
+ )
};

override val reactHost: ReactHost
```

4. Disable Hermes

```diff
Expand Down
6 changes: 5 additions & 1 deletion android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ cmake_minimum_required(VERSION 3.13)
project(react-native-v8)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)
if(${REACT_NATIVE_TARGET_VERSION} GREATER_EQUAL 73)
set (CMAKE_CXX_STANDARD 20)
else()
set (CMAKE_CXX_STANDARD 17)
endif()

string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_TARGET_VERSION=${REACT_NATIVE_TARGET_VERSION} -fexceptions -fno-omit-frame-pointer -frtti -Wno-sign-compare -fstack-protector-all")

Expand Down
10 changes: 4 additions & 6 deletions src/v8runtime/V8Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include "folly/json.h"
#include "v8.h"

namespace react = facebook::react;

namespace rnv8 {

static const char kInspectorName[] = "React Native V8 Inspector";
Expand Down Expand Up @@ -100,7 +98,7 @@ void InspectorFrontend::sendNotification(
client_->SendRemoteMessage(message->string());
}

class LocalConnection : public react::ILocalConnection {
class LocalConnection : public jsinspector::ILocalConnection {
public:
LocalConnection(std::weak_ptr<InspectorClient> weakClient)
: weakClient_(weakClient) {}
Expand Down Expand Up @@ -193,11 +191,11 @@ void InspectorClient::ConnectToReactFrontend() {
std::lock_guard<std::mutex> lock(connectionMutex_);

auto weakClient = CreateWeakPtr();
pageId_ = react::getInspectorInstance().addPage(
pageId_ = jsinspector::getInspectorInstance().addPage(
inspectorName_,
"V8",
[weakClient = std::move(weakClient)](
std::unique_ptr<react::IRemoteConnection> remoteConn) {
std::unique_ptr<jsinspector::IRemoteConnection> remoteConn) {
auto client = weakClient.lock();
if (client) {
client->remoteConn_ = std::move(remoteConn);
Expand All @@ -212,7 +210,7 @@ void InspectorClient::Disconnect() {
if (remoteConn_) {
remoteConn_->onDisconnect();
}
react::getInspectorInstance().removePage(pageId_);
jsinspector::getInspectorInstance().removePage(pageId_);
}

void InspectorClient::DisconnectFromReactFrontend() {
Expand Down
10 changes: 8 additions & 2 deletions src/v8runtime/V8Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@

#include <cxxreact/MessageQueueThread.h>
#include <condition_variable>
#include "jsinspector/InspectorInterfaces.h"
#include "v8-inspector.h"
#if REACT_NATIVE_TARGET_VERSION >= 73
#include "jsinspector-modern/InspectorInterfaces.h"
namespace jsinspector = facebook::react::jsinspector_modern;
#else
#include "jsinspector/InspectorInterfaces.h"
namespace jsinspector = facebook::react;
#endif

namespace rnv8 {

Expand Down Expand Up @@ -84,7 +90,7 @@ class InspectorClient final
v8::Isolate *isolate_;
v8::Global<v8::Context> context_;

std::unique_ptr<facebook::react::IRemoteConnection> remoteConn_;
std::unique_ptr<jsinspector::IRemoteConnection> remoteConn_;
std::string inspectorName_;

std::mutex connectionMutex_;
Expand Down
Loading