mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Do not store .cpp/.h files inside src/main/java - jscexecutor (#34396)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34396 Current we expose native code (.h, .cpp) inside the src/main/java folder. This is making impossible for users on New Architecture to open the project inside Android Studio. The problem is that the src/main/java is reserved to Java/Kotlin sources only. AGP 7.2 also removed support for mixed source roots: https://developer.android.com/studio/releases/gradle-plugin#duplicate-content-roots This is essentially forcing users to write Java code without any autocompletion as all the React Native Java classes are considered C++ files. I'm addressing this issue folder by folder by moving them from ReactAndroid/src/main/java/com/facebook/... to ReactAndroid/src/main/jni/react/... This is the diff for jscexecutor Changelog: [Internal] [Changed] - Do not store .cpp/.h files inside src/main/java - jscexecutor Reviewed By: sshic Differential Revision: D38615007 fbshipit-source-id: e5085130579f37f052b5c8a5702d2c0f1b332bee
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1246300e93
commit
be391844f7
@@ -1,4 +1,4 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_dep", "react_native_target", "react_native_xplat_target", "rn_android_library", "rn_xplat_cxx_library")
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
|
||||
|
||||
rn_android_library(
|
||||
name = "jscexecutor",
|
||||
@@ -13,29 +13,8 @@ rn_android_library(
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
":jni",
|
||||
react_native_target("jni/react/jscexecutor:jni"),
|
||||
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
],
|
||||
)
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "jni",
|
||||
srcs = glob(["*.cpp"]),
|
||||
headers = glob(["*.h"]),
|
||||
header_namespace = "",
|
||||
compiler_flags_enable_exceptions = True, # TODO: is this necessary?
|
||||
compiler_flags_enable_rtti = True, # TODO: is this necessary?
|
||||
fbandroid_allow_jni_merging = True,
|
||||
platforms = ANDROID,
|
||||
soname = "libjscexecutor.$(ext)",
|
||||
visibility = [
|
||||
react_native_target("java/com/facebook/react/jscexecutor:jscexecutor"),
|
||||
],
|
||||
deps = [
|
||||
FBJNI_TARGET,
|
||||
react_native_target("jni/react/jni:jni"),
|
||||
react_native_xplat_target("jsi:JSCRuntime"),
|
||||
react_native_xplat_target("jsiexecutor:jsiexecutor"),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_VERBOSE_MAKEFILE on)
|
||||
|
||||
add_compile_options(-fvisibility=hidden -fexceptions -frtti)
|
||||
|
||||
file(GLOB jscexecutor_SRC CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
add_library(jscexecutor SHARED ${jscexecutor_SRC})
|
||||
|
||||
target_include_directories(jscexecutor PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(jscexecutor
|
||||
jsireact
|
||||
jscruntime
|
||||
fb
|
||||
fbjni
|
||||
folly_runtime
|
||||
jsi
|
||||
reactnativejni)
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <jsi/JSCRuntime.h>
|
||||
#include <jsireact/JSIExecutor.h>
|
||||
#include <react/jni/JReactMarker.h>
|
||||
#include <react/jni/JSLogging.h>
|
||||
#include <react/jni/JavaScriptExecutorHolder.h>
|
||||
#include <react/jni/NativeTime.h>
|
||||
#include <react/jni/ReadableNativeMap.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
namespace {
|
||||
|
||||
class JSCExecutorFactory : public JSExecutorFactory {
|
||||
public:
|
||||
std::unique_ptr<JSExecutor> createJSExecutor(
|
||||
std::shared_ptr<ExecutorDelegate> delegate,
|
||||
std::shared_ptr<MessageQueueThread> jsQueue) override {
|
||||
auto installBindings = [](jsi::Runtime &runtime) {
|
||||
react::Logger androidLogger =
|
||||
static_cast<void (*)(const std::string &, unsigned int)>(
|
||||
&reactAndroidLoggingHook);
|
||||
react::bindNativeLogger(runtime, androidLogger);
|
||||
|
||||
react::PerformanceNow androidNativePerformanceNow =
|
||||
static_cast<double (*)()>(&reactAndroidNativePerformanceNowHook);
|
||||
react::bindNativePerformanceNow(runtime, androidNativePerformanceNow);
|
||||
};
|
||||
return std::make_unique<JSIExecutor>(
|
||||
jsc::makeJSCRuntime(),
|
||||
delegate,
|
||||
JSIExecutor::defaultTimeoutInvoker,
|
||||
installBindings);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// This is not like JSCJavaScriptExecutor, which calls JSC directly. This uses
|
||||
// JSIExecutor with JSCRuntime.
|
||||
class JSCExecutorHolder
|
||||
: public jni::HybridClass<JSCExecutorHolder, JavaScriptExecutorHolder> {
|
||||
public:
|
||||
static constexpr auto kJavaDescriptor =
|
||||
"Lcom/facebook/react/jscexecutor/JSCExecutor;";
|
||||
|
||||
static jni::local_ref<jhybriddata> initHybrid(
|
||||
jni::alias_ref<jclass>,
|
||||
ReadableNativeMap *) {
|
||||
// This is kind of a weird place for stuff, but there's no other
|
||||
// good place for initialization which is specific to JSC on
|
||||
// Android.
|
||||
JReactMarker::setLogPerfMarkerIfNeeded();
|
||||
// TODO mhorowitz T28461666 fill in some missing nice to have glue
|
||||
return makeCxxInstance(std::make_unique<JSCExecutorFactory>());
|
||||
}
|
||||
|
||||
static void registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", JSCExecutorHolder::initHybrid),
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
using HybridBase::HybridBase;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
return facebook::jni::initialize(
|
||||
vm, [] { facebook::react::JSCExecutorHolder::registerNatives(); });
|
||||
}
|
||||
Reference in New Issue
Block a user