Android: consolidate various prebuilt C++ .so configuration into Android-prebuilt.mk

Summary:
To make it easier for hosting app or other lib to get access to the ReactAndroidNdk .so outputs, let's define common targets in a dedicated Android-prebuilt.mk. Hosting app's Android.mk just need to include the mk path.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D23938538

fbshipit-source-id: 850d690326d134212d5f040c6fa54ab50c53cb87
This commit is contained in:
Kevin Gozali
2020-09-25 22:14:56 -07:00
committed by Facebook GitHub Bot
parent 14042fb76f
commit 45a4a67965
3 changed files with 99 additions and 61 deletions
+94
View File
@@ -0,0 +1,94 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# This configuration provides access to most common React Native prebuilt .so files
# to avoid recompiling each of the libraries outside of ReactAndroid NDK compilation.
# Hosting app's/library's Android.mk can include this Android-prebuilt.mk file to
# get access to those .so to depend on.
# NOTES:
# * Currently, it assumes building React Native from source.
# * Not every .so is listed here (yet).
# * Static libs are not covered here (yet).
LOCAL_PATH := $(call my-dir)
REACT_ANDROID_DIR := $(LOCAL_PATH)
# TODO: Find a better way without pointing to ReactAndroid/build dir.
REACT_ANDROID_BUILD_DIR := $(REACT_ANDROID_DIR)/build
FIRST_PARTY_NDK_DIR := $(REACT_ANDROID_DIR)/src/main/jni/first-party
THIRD_PARTY_NDK_DIR := $(REACT_ANDROID_BUILD_DIR)/third-party-ndk
REACT_ANDROID_SRC_DIR := $(REACT_ANDROID_DIR)/src/main
REACT_COMMON_DIR := $(REACT_ANDROID_DIR)/../ReactCommon
REACT_GENERATED_SRC_DIR := $(REACT_ANDROID_BUILD_DIR)/generated/source
# Note: this only have .so, not .a
REACT_NDK_EXPORT_DIR := $(REACT_ANDROID_BUILD_DIR)/react-ndk/exported
# fb
include $(CLEAR_VARS)
LOCAL_MODULE := fb
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libfb.so
LOCAL_EXPORT_C_INCLUDES := $(FIRST_PARTY_NDK_DIR)/fb/include
include $(PREBUILT_SHARED_LIBRARY)
# folly_json
include $(CLEAR_VARS)
LOCAL_MODULE := folly_json
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libfolly_json.so
LOCAL_EXPORT_C_INCLUDES := \
$(THIRD_PARTY_NDK_DIR)/boost/boost_1_63_0 \
$(THIRD_PARTY_NDK_DIR)/double-conversion \
$(THIRD_PARTY_NDK_DIR)/folly \
$(THIRD_PARTY_NDK_DIR)/glog/exported
# Note: Sync with folly/Android.mk.
FOLLY_FLAGS := \
-DFOLLY_NO_CONFIG=1 \
-DFOLLY_HAVE_CLOCK_GETTIME=1 \
-DFOLLY_HAVE_MEMRCHR=1 \
-DFOLLY_USE_LIBCPP=1 \
-DFOLLY_MOBILE=1 \
-DFOLLY_HAVE_XSI_STRERROR_R=1
LOCAL_CFLAGS += $(FOLLY_FLAGS)
LOCAL_EXPORT_CPPFLAGS := $(FOLLY_FLAGS)
include $(PREBUILT_SHARED_LIBRARY)
# folly_futures
include $(CLEAR_VARS)
LOCAL_MODULE := folly_futures
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libfolly_futures.so
LOCAL_SHARED_LIBRARIES := liblibfolly_json
include $(PREBUILT_SHARED_LIBRARY)
# react_nativemodule_core
include $(CLEAR_VARS)
LOCAL_MODULE := react_nativemodule_core
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libreact_nativemodule_core.so
LOCAL_EXPORT_C_INCLUDES := \
$(REACT_ANDROID_SRC_DIR)/jni \
$(REACT_COMMON_DIR)/callinvoker \
$(REACT_COMMON_DIR)/jsi \
$(REACT_COMMON_DIR)/react/nativemodule/core \
$(REACT_COMMON_DIR)/react/nativemodule/core/platform/android
LOCAL_SHARED_LIBRARIES := libfolly_json
include $(PREBUILT_SHARED_LIBRARY)
# react_nativemodule_manager
include $(CLEAR_VARS)
LOCAL_MODULE := react_nativemodule_manager
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libreact_nativemodule_manager.so
LOCAL_EXPORT_C_INCLUDES := \
$(REACT_ANDROID_SRC_DIR)/java/com/facebook/react/turbomodule/core/jni
include $(PREBUILT_SHARED_LIBRARY)
# react_codegen_reactandroidspec
include $(CLEAR_VARS)
LOCAL_MODULE := react_codegen_reactandroidspec
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libreact_codegen_reactandroidspec.so
LOCAL_EXPORT_C_INCLUDES := \
$(REACT_GENERATED_SRC_DIR)/codegen/jni
include $(PREBUILT_SHARED_LIBRARY)
# fbjni
include $(FIRST_PARTY_NDK_DIR)/fbjni/Android.mk
+1 -8
View File
@@ -187,7 +187,6 @@ android {
if (enableCodegen) {
def reactAndroidProjectDir = project(':ReactAndroid').projectDir;
def reactAndroidBuildDir = project(':ReactAndroid').buildDir;
android {
defaultConfig {
externalNativeBuild {
@@ -197,14 +196,8 @@ if (enableCodegen) {
"APP_STL=c++_shared",
"NDK_TOOLCHAIN_VERSION=clang",
// The following paths assume building React Native from source.
// TODO: Find a better way without pointing to ReactAndroid/build dir.
"GENERATED_SRC_DIR=$buildDir/generated/source",
"REACT_ANDROID_SRC_DIR=$reactAndroidProjectDir/src/main",
"REACT_COMMON_DIR=$rootDir/ReactCommon",
"REACT_GENERATED_SRC_DIR=$reactAndroidBuildDir/generated/source",
"REACT_NDK_EXPORT_DIR=$reactAndroidBuildDir/tmp/buildReactNdkLib/local",
"FIRST_PARTY_NDK_DIR=$reactAndroidProjectDir/src/main/jni/first-party",
"THIRD_PARTY_NDK_DIR=$reactAndroidBuildDir/third-party-ndk"
"REACT_ANDROID_DIR=$reactAndroidProjectDir"
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
cppFlags "-std=c++1y"
targets "rntester_appmodules"
@@ -3,60 +3,11 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
LOCAL_PATH := $(call my-dir)
THIS_DIR := $(call my-dir)
#############################################
# Prebuilt libraries off ReactAndroid build #
#############################################
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
include $(CLEAR_VARS)
LOCAL_MODULE := react_nativemodule_core
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libreact_nativemodule_core.so
# TODO: These needs to be synced with the other Android.mk files -- not efficient.
# Note: By doing this, it delegates all header includes lookup to this .so.
LOCAL_EXPORT_C_INCLUDES := \
$(FIRST_PARTY_NDK_DIR)/fbjni/headers \
$(REACT_ANDROID_SRC_DIR)/jni \
$(REACT_COMMON_DIR)/callinvoker \
$(REACT_COMMON_DIR)/jsi \
$(REACT_COMMON_DIR)/react/nativemodule/core \
$(REACT_COMMON_DIR)/react/nativemodule/core/platform/android \
$(REACT_GENERATED_SRC_DIR)/codegen/jni \
$(THIRD_PARTY_NDK_DIR)/boost/boost_1_63_0 \
$(THIRD_PARTY_NDK_DIR)/double-conversion \
$(THIRD_PARTY_NDK_DIR)/folly \
$(THIRD_PARTY_NDK_DIR)/glog/exported
# Note: Sync with folly/Android.mk.
FOLLY_FLAGS := \
-DFOLLY_NO_CONFIG=1 \
-DFOLLY_HAVE_CLOCK_GETTIME=1 \
-DFOLLY_HAVE_MEMRCHR=1 \
-DFOLLY_USE_LIBCPP=1 \
-DFOLLY_MOBILE=1 \
-DFOLLY_HAVE_XSI_STRERROR_R=1
LOCAL_CFLAGS += $(FOLLY_FLAGS)
LOCAL_EXPORT_CPPFLAGS := $(FOLLY_FLAGS)
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := react_nativemodule_manager
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libreact_nativemodule_manager.so
LOCAL_EXPORT_C_INCLUDES := \
$(REACT_ANDROID_SRC_DIR)/java/com/facebook/react/turbomodule/core/jni
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := react_codegen_reactandroidspec
LOCAL_SRC_FILES := $(REACT_NDK_EXPORT_DIR)/$(TARGET_ARCH_ABI)/libreact_codegen_reactandroidspec.so
LOCAL_EXPORT_C_INCLUDES := \
$(REACT_GENERATED_SRC_DIR)/codegen/jni
include $(PREBUILT_SHARED_LIBRARY)
####################################
# RNTester app specific definition #
####################################
LOCAL_PATH := $(THIS_DIR)
include $(CLEAR_VARS)
LOCAL_MODULE := rntester_appmodules
@@ -64,7 +15,7 @@ LOCAL_MODULE := rntester_appmodules
LOCAL_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni
LOCAL_SHARED_LIBRARIES := libreact_nativemodule_core libreact_nativemodule_manager libreact_codegen_reactandroidspec
LOCAL_SHARED_LIBRARIES := libfbjni libreact_nativemodule_core libreact_nativemodule_manager libreact_codegen_reactandroidspec
LOCAL_CFLAGS := \
-DLOG_TAG=\"ReactNative\"
LOCAL_CFLAGS += -fexceptions -frtti -std=c++14 -Wall