Skip to content

Commit e7a4de2

Browse files
cortinicokikoso
authored andcommitted
Create a debugOptimized buildType for Android (facebook#52648)
Summary: Pull Request resolved: facebook#52648 This creates a `debugOptimized` build type for React Native Android, meaning that we can run C++ optimization on the debug build, while still having the debugger enabled. This is aimed at improving the developer experience for folks developing on low-end devices or emulators. Users that intend to debug can still use the `debug` variant where the full debug symbols are shipped. Changelog: [ANDROID] [ADDED] - Create a debugOptimized buildType for Android Reviewed By: cipolleschi Differential Revision: D78425138 fbshipit-source-id: c1e9ea3608e7df10fb871a5584352f0747cf560b
1 parent c8e3c26 commit e7a4de2

File tree

13 files changed

+50
-15
lines changed

13 files changed

+50
-15
lines changed

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactExtension.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ abstract class ReactExtension @Inject constructor(val project: Project) {
100100
* Allows to specify the debuggable variants (by default just 'debug'). Variants in this list will
101101
* not be bundled (the bundle file will not be created and won't be copied over).
102102
*
103-
* Default: ['debug']
103+
* Default: ['debug', 'debugOptimized']
104104
*/
105105
val debuggableVariants: ListProperty<String> =
106-
objects.listProperty(String::class.java).convention(listOf("debug"))
106+
objects.listProperty(String::class.java).convention(listOf("debug", "debugOptimized"))
107107

108108
/** Hermes Config */
109109

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ internal object AgpConfiguratorUtils {
4242
getByName("release").apply {
4343
manifestPlaceholders["usesCleartextTraffic"] = "false"
4444
}
45+
maybeCreate("debugOptimized").apply {
46+
manifestPlaceholders["usesCleartextTraffic"] = "true"
47+
initWith(debug)
48+
externalNativeBuild {
49+
cmake {
50+
arguments("-DCMAKE_BUILD_TYPE=Release")
51+
matchingFallbacks += listOf("release")
52+
}
53+
}
54+
}
4555
}
4656
}
4757
}

packages/react-native/ReactAndroid/build.gradle.kts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,23 @@ android {
599599
publishing {
600600
multipleVariants {
601601
withSourcesJar()
602-
includeBuildTypeValues("debug", "release")
602+
includeBuildTypeValues("debug", "release", "debugOptimized")
603603
}
604604
}
605605

606606
testOptions {
607607
unitTests { isIncludeAndroidResources = true }
608608
targetSdk = libs.versions.targetSdk.get().toInt()
609609
}
610+
611+
buildTypes {
612+
create("debugOptimized") {
613+
initWith(getByName("debug"))
614+
externalNativeBuild {
615+
cmake { arguments("-DCMAKE_BUILD_TYPE=Release", "-DREACT_NATIVE_DEBUG_OPTIMIZED=True") }
616+
}
617+
}
618+
}
610619
}
611620

612621
tasks.withType<KotlinCompile>().configureEach {

packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ android {
306306
}
307307
}
308308
}
309+
buildTypes {
310+
create("debugOptimized") {
311+
initWith(getByName("debug"))
312+
externalNativeBuild { cmake { arguments("-DCMAKE_BUILD_TYPE=Release") } }
313+
}
314+
}
309315
}
310316

311317
sourceSets.getByName("main") {

packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ target_link_libraries(
2525
reactnative
2626
)
2727
target_compile_reactnative_options(hermes_executor PRIVATE)
28-
target_compile_options(hermes_executor PRIVATE $<$<CONFIG:Debug>:-DHERMES_ENABLE_DEBUGGER=1>)
28+
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED)
29+
target_compile_options(hermes_executor PRIVATE -DHERMES_ENABLE_DEBUGGER=1)
30+
endif()

packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ target_link_libraries(hermesinstancejni
2727
)
2828

2929
target_compile_reactnative_options(hermesinstancejni PRIVATE)
30-
target_compile_options(hermesinstancejni PRIVATE $<$<CONFIG:Debug>:-DHERMES_ENABLE_DEBUGGER=1>)
30+
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED)
31+
target_compile_options(hermesinstancejni PRIVATE -DHERMES_ENABLE_DEBUGGER=1)
32+
endif ()

packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ add_library(rninstance
1717
)
1818

1919
target_compile_reactnative_options(rninstance PRIVATE)
20-
target_compile_options(rninstance PRIVATE $<$<CONFIG:Debug>:-DHERMES_ENABLE_DEBUGGER=1>)
20+
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED)
21+
target_compile_options(rninstance PRIVATE -DHERMES_ENABLE_DEBUGGER=1)
22+
endif ()
2123

2224
target_merge_so(rninstance)
2325
target_include_directories(rninstance PUBLIC .)

packages/react-native/ReactCommon/hermes/executor/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ target_link_libraries(hermes_executor_common
2626
)
2727

2828
target_compile_reactnative_options(hermes_executor_common PRIVATE)
29-
if(${CMAKE_BUILD_TYPE} MATCHES Debug)
29+
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED)
3030
target_compile_options(
3131
hermes_executor_common
3232
PRIVATE

packages/react-native/ReactCommon/hermes/inspector-modern/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ add_library(hermes_inspector_modern
1717

1818
target_compile_reactnative_options(hermes_inspector_modern PRIVATE)
1919

20-
if(${CMAKE_BUILD_TYPE} MATCHES Debug)
20+
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED)
2121
target_compile_options(
2222
hermes_inspector_modern
2323
PRIVATE

packages/react-native/ReactCommon/jsinspector-modern/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ target_link_libraries(jsinspector
2828
reactperflogger
2929
)
3030
target_compile_reactnative_options(jsinspector PRIVATE)
31-
target_compile_options(jsinspector PRIVATE
32-
$<$<CONFIG:Debug>:-DREACT_NATIVE_DEBUGGER_ENABLED=1>
33-
$<$<CONFIG:Debug>:-DREACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1>
34-
)
31+
if(${CMAKE_BUILD_TYPE} MATCHES Debug OR REACT_NATIVE_DEBUG_OPTIMIZED)
32+
target_compile_options(jsinspector PRIVATE
33+
-DREACT_NATIVE_DEBUGGER_ENABLED=1
34+
-DREACT_NATIVE_DEBUGGER_ENABLED_DEVONLY=1
35+
)
36+
endif ()

0 commit comments

Comments
 (0)