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 - reactnativeblob (#34421)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34421 Currently 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 reactnativeblob Changelog: [Internal] [Changed] - Do not store .cpp/.h files inside src/main/java - reactnativeblob Reviewed By: cipolleschi Differential Revision: D38703092 fbshipit-source-id: 3d4391d8ee5587b199efa4001f68c6d4ed3ce2c2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f96d5931c0
commit
d35aab45b9
@@ -31,7 +31,7 @@ rn_android_library(
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
react_native_target("java/com/facebook/react/common:common"),
|
||||
react_native_target("java/com/facebook/react/module/annotations:annotations"),
|
||||
react_native_target("java/com/facebook/react/modules/blob/jni:jni"),
|
||||
react_native_target("jni/react/reactnativeblob:jni"),
|
||||
react_native_target("java/com/facebook/react/modules/network:network"),
|
||||
react_native_target("java/com/facebook/react/modules/websocket:websocket"),
|
||||
],
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_dep", "rn_xplat_cxx_library")
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "jni",
|
||||
srcs = glob(["*.cpp"]),
|
||||
headers = glob(["*.h"]),
|
||||
header_namespace = "",
|
||||
labels = [
|
||||
"pfh:ReactNative_CommonInfrastructurePlaceholder",
|
||||
"supermodule:xplat/default/public.react_native.infra",
|
||||
],
|
||||
platforms = ANDROID,
|
||||
soname = "libreactnativeblob.$(ext)",
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
react_native_target("jni/react/jni:jni"),
|
||||
FBJNI_TARGET,
|
||||
react_native_xplat_dep("jsi:jsi"),
|
||||
],
|
||||
)
|
||||
@@ -1,67 +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 "BlobCollector.h"
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
using namespace facebook;
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
static constexpr auto kBlobModuleJavaDescriptor =
|
||||
"com/facebook/react/modules/blob/BlobModule";
|
||||
|
||||
BlobCollector::BlobCollector(
|
||||
jni::global_ref<jobject> blobModule,
|
||||
const std::string &blobId)
|
||||
: blobModule_(blobModule), blobId_(blobId) {}
|
||||
|
||||
BlobCollector::~BlobCollector() {
|
||||
jni::ThreadScope::WithClassLoader([&] {
|
||||
static auto removeMethod = jni::findClassStatic(kBlobModuleJavaDescriptor)
|
||||
->getMethod<void(jstring)>("remove");
|
||||
removeMethod(blobModule_, jni::make_jstring(blobId_).get());
|
||||
blobModule_.reset();
|
||||
});
|
||||
}
|
||||
|
||||
void BlobCollector::nativeInstall(
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jni::alias_ref<jobject> blobModule,
|
||||
jlong jsContextNativePointer) {
|
||||
auto &runtime = *((jsi::Runtime *)jsContextNativePointer);
|
||||
auto blobModuleRef = jni::make_global(blobModule);
|
||||
runtime.global().setProperty(
|
||||
runtime,
|
||||
"__blobCollectorProvider",
|
||||
jsi::Function::createFromHostFunction(
|
||||
runtime,
|
||||
jsi::PropNameID::forAscii(runtime, "__blobCollectorProvider"),
|
||||
1,
|
||||
[blobModuleRef](
|
||||
jsi::Runtime &rt,
|
||||
const jsi::Value &thisVal,
|
||||
const jsi::Value *args,
|
||||
size_t count) {
|
||||
auto blobId = args[0].asString(rt).utf8(rt);
|
||||
auto blobCollector =
|
||||
std::make_shared<BlobCollector>(blobModuleRef, blobId);
|
||||
return jsi::Object::createFromHostObject(rt, blobCollector);
|
||||
}));
|
||||
}
|
||||
|
||||
void BlobCollector::registerNatives() {
|
||||
registerHybrid(
|
||||
{makeNativeMethod("nativeInstall", BlobCollector::nativeInstall)});
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,42 +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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class BlobCollector : public jni::HybridClass<BlobCollector>,
|
||||
public jsi::HostObject {
|
||||
public:
|
||||
BlobCollector(
|
||||
jni::global_ref<jobject> blobManager,
|
||||
const std::string &blobId);
|
||||
~BlobCollector();
|
||||
|
||||
static constexpr auto kJavaDescriptor =
|
||||
"Lcom/facebook/react/modules/blob/BlobCollector;";
|
||||
|
||||
static void nativeInstall(
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jni::alias_ref<jobject> blobModule,
|
||||
jlong jsContextNativePointer);
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
|
||||
jni::global_ref<jobject> blobModule_;
|
||||
const std::string blobId_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,22 +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 reactnativeblob_SRC CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
add_library(reactnativeblob SHARED ${reactnativeblob_SRC})
|
||||
|
||||
target_include_directories(reactnativeblob PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(reactnativeblob
|
||||
jsireact
|
||||
fb
|
||||
fbjni
|
||||
folly_runtime
|
||||
jsi
|
||||
reactnativejni)
|
||||
@@ -1,15 +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 "BlobCollector.h"
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
return facebook::jni::initialize(
|
||||
vm, [] { facebook::react::BlobCollector::registerNatives(); });
|
||||
}
|
||||
Reference in New Issue
Block a user