Skip to content

Commit 6b4e526

Browse files
Kudofacebook-github-bot
authored andcommitted
Add debug build support for Android native code (#25147)
Summary: With JSI based architecture, there will be more and more C++ native code involved. Original NDK builder in RN only supports release build and that's not reasonable for native debugging. This change introduces a way to build native code in debuggable version. Simply add `NATIVE_BUILD_TYPE=Debug` environment variable during gradle build, e.g. `NATIVE_BUILD_TYPE=Debug ./gradlew clean :ReactAndroid:assembleDebug` ## Changelog [Android] [Added] - Add native debug build support to improve debugging DX Pull Request resolved: #25147 Differential Revision: D15628533 Pulled By: cpojer fbshipit-source-id: 8f5b54c4580824452d2a1236a7bd641889b001ec
1 parent dbad0fd commit 6b4e526

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

ReactAndroid/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def dependenciesPath = System.getenv("REACT_NATIVE_DEPENDENCIES")
3333
// and the build will use that.
3434
def boostPath = dependenciesPath ?: System.getenv("REACT_NATIVE_BOOST_PATH")
3535

36+
// Setup build type for NDK, supported values: {debug, release}
37+
def nativeBuildType = System.getenv("NATIVE_BUILD_TYPE") ?: "release"
38+
3639
task createNativeDepsDirectories {
3740
downloadsDir.mkdirs()
3841
thirdPartyNdkDir.mkdirs()
@@ -225,6 +228,7 @@ task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConvers
225228
inputs.dir("src/main/java/com/facebook/react/modules/blob")
226229
outputs.dir("$buildDir/react-ndk/all")
227230
commandLine(getNdkBuildFullPath(),
231+
"NDK_DEBUG=" + (nativeBuildType.equalsIgnoreCase("debug") ? "1" : "0"),
228232
"NDK_PROJECT_PATH=null",
229233
"NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk",
230234
"NDK_OUT=" + temporaryDir,

ReactAndroid/src/main/jni/react/jni/Android.mk

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ LOCAL_MODULE := reactnativejni
3636
# Compile all local c++ files.
3737
LOCAL_SRC_FILES := $(wildcard *.cpp)
3838

39+
ifeq ($(APP_OPTIM),debug)
40+
# Keep symbols by overriding the strip command invoked by ndk-build.
41+
# Note that this will apply to all shared libraries,
42+
# i.e. shared libraries will NOT be stripped
43+
# even though we override it in this Android.mk
44+
cmd-strip :=
45+
endif
46+
3947
# Build the files in this directory as a shared library
4048
include $(BUILD_SHARED_LIBRARY)
4149

ReactAndroid/src/main/jni/third-party/folly/Android.mk

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ LOCAL_SRC_FILES:= \
1717
folly/container/detail/F14Table.cpp \
1818
folly/ScopeGuard.cpp \
1919

20+
ifeq ($(APP_OPTIM),debug)
21+
LOCAL_SRC_FILES += \
22+
folly/lang/Assume.cpp \
23+
folly/lang/SafeAssert.cpp \
24+
folly/FileUtil.cpp \
25+
folly/portability/SysUio.cpp
26+
endif
27+
2028
LOCAL_C_INCLUDES := $(LOCAL_PATH)
2129
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
2230

0 commit comments

Comments
 (0)