From 06e55ec5ea607a5a0b704ca2fcff53e8ee2ce157 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 8 Mar 2023 05:38:55 -0800 Subject: [PATCH] Avoid double glog init internally Summary: glog logging was being sent to adb logcat twice since `fbgloginit` uses `force_static = True` and was being linked as two separate copies. Changelog: [Internal] Reviewed By: sshic Differential Revision: D43842295 fbshipit-source-id: da4233d29dbddc2b3cefdca979c873479672b11c --- ReactAndroid/src/main/jni/react/jni/BUCK | 9 +++++---- ReactAndroid/src/main/jni/react/jni/OnLoad.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/jni/BUCK b/ReactAndroid/src/main/jni/react/jni/BUCK index 5ce1930b4e2..23c189053a8 100644 --- a/ReactAndroid/src/main/jni/react/jni/BUCK +++ b/ReactAndroid/src/main/jni/react/jni/BUCK @@ -1,4 +1,4 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "IS_OSS_BUILD", "react_native_target", "react_native_xplat_dep", "react_native_xplat_target", "rn_xplat_cxx_library") +load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBGLOGINIT_TARGET", "FBJNI_TARGET", "IS_OSS_BUILD", "react_native_target", "react_native_xplat_dep", "react_native_xplat_target", "rn_xplat_cxx_library") EXPORTED_HEADERS = [ "CxxModuleWrapper.h", @@ -48,7 +48,7 @@ rn_xplat_cxx_library( "-DLOG_TAG=\"ReactNativeJNI\"", "-DWITH_FBSYSTRACE=1", "-DWITH_INSPECTOR=1", - ], + ] + ["-DWITH_GLOGINIT=0"] if not IS_OSS_BUILD else [], soname = "libreactnativejni.$(ext)", visibility = [ "PUBLIC", @@ -59,7 +59,6 @@ rn_xplat_cxx_library( "//third-party/glog:glog", "//xplat/folly:dynamic", "//xplat/folly:json", - "//fbandroid/xplat/fbgloginit:fbgloginit", "//xplat/fbsystrace:fbsystrace", react_native_target("jni/react/turbomodule:callinvokerholder"), react_native_xplat_target("cxxreact:bridge"), @@ -71,5 +70,7 @@ rn_xplat_cxx_library( react_native_xplat_target("logger:logger"), react_native_xplat_dep("jsi:jsi"), FBJNI_TARGET, - ] if not IS_OSS_BUILD else [], + ] + ([ + FBGLOGINIT_TARGET, + ] if IS_OSS_BUILD else []), ) diff --git a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp index cbcaa77eb1d..5dd3d186098 100644 --- a/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jni/OnLoad.cpp @@ -25,6 +25,10 @@ #include "JInspector.h" #endif +#ifndef WITH_GLOGINIT +#define WITH_GLOGINIT 1 +#endif + using namespace facebook::jni; namespace facebook { @@ -67,8 +71,10 @@ class ProxyJavaScriptExecutorHolder : public HybridClass< extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { return initialize(vm, [] { +#if WITH_GLOGINIT gloginit::initialize(); FLAGS_minloglevel = 0; +#endif ProxyJavaScriptExecutorHolder::registerNatives(); CatalystInstanceImpl::registerNatives(); CxxModuleWrapperBase::registerNatives();