From 084d878a05fb2ccb8992eb8dc44c1fd0d4be11e5 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 18 Jul 2025 08:07:54 -0700 Subject: [PATCH] Migrate RNTester to use `{usesCleartextTraffic}` Manifest Placeholder (#52620) Summary: 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 Pull Request resolved: https://github.com/facebook/react-native/pull/52620 Test Plan: Tested locally with RNTester by doing: ``` ./gradlew installDebugOptimized ``` This is the output of the 3 generated .aar. The size difference is a proof that we're correctly stripping out the C++ debug symbols: Screenshot 2025-07-15 at 17 49 50 Screenshot 2025-07-15 at 17 49 39 Screenshot 2025-07-15 at 17 49 32 Rollback Plan: Reviewed By: cipolleschi Differential Revision: D78351347 Pulled By: cortinico fbshipit-source-id: 568a484ba8d2ee6e089cabc95451938e853fbc54 --- .../kotlin/com/facebook/react/ReactPlugin.kt | 2 ++ .../react/utils/AgpConfiguratorUtils.kt | 21 +++++++++++++++++++ .../android/app/src/debug/AndroidManifest.xml | 8 ------- .../android/app/src/main/AndroidManifest.xml | 1 + 4 files changed, 24 insertions(+), 8 deletions(-) delete mode 100644 packages/rn-tester/android/app/src/debug/AndroidManifest.xml diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 85f8ca32aaf..3d40455a43a 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -18,6 +18,7 @@ import com.facebook.react.tasks.GenerateEntryPointTask import com.facebook.react.tasks.GeneratePackageListTask import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForApp import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFieldsForLibraries +import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildTypesForApp import com.facebook.react.utils.AgpConfiguratorUtils.configureDevServerLocation import com.facebook.react.utils.AgpConfiguratorUtils.configureNamespaceForLibraries import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap @@ -84,6 +85,7 @@ class ReactPlugin : Plugin { configureAutolinking(project, extension) configureCodegen(project, extension, rootExtension, isLibrary = false) configureResources(project, extension) + configureBuildTypesForApp(project) } // Library Only Configuration diff --git a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt index f8bee6923f9..f33353349b2 100644 --- a/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt +++ b/packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/AgpConfiguratorUtils.kt @@ -19,6 +19,7 @@ import java.net.Inet4Address import java.net.NetworkInterface import javax.xml.parsers.DocumentBuilder import javax.xml.parsers.DocumentBuilderFactory +import kotlin.plus import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.plugins.AppliedPlugin @@ -27,6 +28,26 @@ import org.w3c.dom.Element @Suppress("UnstableApiUsage") internal object AgpConfiguratorUtils { + fun configureBuildTypesForApp(project: Project) { + val action = + Action { + project.extensions + .getByType(ApplicationAndroidComponentsExtension::class.java) + .finalizeDsl { ext -> + ext.buildTypes { + val debug = + getByName("debug").apply { + manifestPlaceholders["usesCleartextTraffic"] = "true" + } + getByName("release").apply { + manifestPlaceholders["usesCleartextTraffic"] = "false" + } + } + } + } + project.pluginManager.withPlugin("com.android.application", action) + } + fun configureBuildConfigFieldsForApp(project: Project, extension: ReactExtension) { val action = Action { diff --git a/packages/rn-tester/android/app/src/debug/AndroidManifest.xml b/packages/rn-tester/android/app/src/debug/AndroidManifest.xml deleted file mode 100644 index fa26aa56e1c..00000000000 --- a/packages/rn-tester/android/app/src/debug/AndroidManifest.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - diff --git a/packages/rn-tester/android/app/src/main/AndroidManifest.xml b/packages/rn-tester/android/app/src/main/AndroidManifest.xml index bd35388167b..a842f3a0d29 100644 --- a/packages/rn-tester/android/app/src/main/AndroidManifest.xml +++ b/packages/rn-tester/android/app/src/main/AndroidManifest.xml @@ -50,6 +50,7 @@