Do not store .cpp/.h files inside src/main/java - reactperflogger (#34386)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34386

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 reactperflogger

Changelog:
[Internal] [Changed] - Do not store .cpp/.h files inside src/main/java - reactperflogger

Reviewed By: cipolleschi

Differential Revision: D38584681

fbshipit-source-id: 8b65b3fa47a7f106c7fea79fd739f0e4e37efa2a
This commit is contained in:
Nicola Corti
2022-08-12 05:05:39 -07:00
committed by Facebook GitHub Bot
parent 7783f88d71
commit 296d7db7a2
8 changed files with 4 additions and 3 deletions
@@ -20,6 +20,6 @@ rn_android_library(
deps = [
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
react_native_dep("libraries/fbjni:java"),
react_native_target("java/com/facebook/react/reactperflogger/jni:jni"),
react_native_target("jni/react/reactperflogger:jni"),
],
)
@@ -1,32 +0,0 @@
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_xplat_target", "rn_xplat_cxx_library")
rn_xplat_cxx_library(
name = "jni",
srcs = [
"reactperflogger/OnLoad.cpp",
],
header_namespace = "",
exported_headers = {
"reactperflogger/JNativeModulePerfLogger.h": "reactperflogger/JNativeModulePerfLogger.h",
},
fbandroid_allow_jni_merging = True,
fbandroid_labels = [
"supermodule:xplat/default/public.react_native.infra",
],
labels = ["pfh:ReactNative_CommonInfrastructurePlaceholder"],
platforms = ANDROID,
preprocessor_flags = [
"-DLOG_TAG=\"ReactNative\"",
"-DWITH_FBSYSTRACE=1",
],
soname = "libreactperfloggerjni.$(ext)",
visibility = [
"PUBLIC",
],
deps = [
FBJNI_TARGET,
],
exported_deps = [
react_native_xplat_target("reactperflogger:reactperflogger"),
],
)
@@ -1,24 +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(-fexceptions -frtti -std=c++17 -Wall)
add_library(reactperfloggerjni SHARED reactperflogger/OnLoad.cpp)
target_include_directories(reactperfloggerjni
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/reactperflogger
)
target_link_libraries(reactperfloggerjni
fb
fbjni
android
reactperflogger)
@@ -1,5 +0,0 @@
---
Checks: '>
clang-diagnostic-*,
'
...
@@ -1,30 +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 <reactperflogger/NativeModulePerfLogger.h>
#include <memory>
namespace facebook {
namespace react {
class JNativeModulePerfLogger
: public jni::HybridClass<JNativeModulePerfLogger> {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/perflogger/NativeModulePerfLogger;";
virtual std::unique_ptr<facebook::react::NativeModulePerfLogger> get() = 0;
private:
friend HybridBase;
};
} // namespace react
} // namespace facebook
@@ -1,14 +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 "JNativeModulePerfLogger.h"
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(vm, [] {});
}
@@ -36,7 +36,7 @@ rn_xplat_cxx_library(
react_native_xplat_shared_library_target("jsi:jsi"),
react_native_xplat_target("react/nativemodule/core:core"),
react_native_xplat_target("runtimeexecutor:runtimeexecutor"),
react_native_target("java/com/facebook/react/reactperflogger/jni:jni"),
react_native_target("jni/react/reactperflogger:jni"),
],
)