Skip to content

Commit 9a9c6e5

Browse files
committed
Add IgnoreStringLiterals in DefaultDevSupportManagerFactory class (#50608)
Summary: Pull Request resolved: #50608 Adding IgnoreStringLiterals in DefaultDevSupportManagerFactory class to prevent proguard to keep the BridgeDevSupportManager class changelog: [internal] internal Reviewed By: alanleedev Differential Revision: D72090836
1 parent 0df71ea commit 9a9c6e5

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DefaultDevSupportManagerFactory.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import com.facebook.react.devsupport.interfaces.DevSupportManager
1616
import com.facebook.react.devsupport.interfaces.PausedInDebuggerOverlayManager
1717
import com.facebook.react.devsupport.interfaces.RedBoxHandler
1818
import com.facebook.react.packagerconnection.RequestHandler
19+
import com.facebook.redex.annotations.IgnoreStringLiterals
1920

2021
/**
2122
* A simple factory that creates instances of [DevSupportManager] implementations. Uses reflection
2223
* to create BridgeDevSupportManager if it exists. This allows ProGuard to strip that class and its
2324
* dependencies in release builds. If the class isn't found, [PerftestDevSupportManager] is returned
2425
* instead.
2526
*/
27+
@IgnoreStringLiterals
2628
internal class DefaultDevSupportManagerFactory : DevSupportManagerFactory {
2729

2830
override fun create(
@@ -47,15 +49,9 @@ internal class DefaultDevSupportManagerFactory : DevSupportManagerFactory {
4749
// trying to return the full support DevSupportManager and if it fails, then just
4850
// return PerftestDevSupportManager.
4951

50-
// ProGuard is surprisingly smart in this case and will keep a class if it detects a call
51-
// to
52-
// Class.forName() with a static string. So instead we generate a quasi-dynamic string to
53-
// confuse it.
54-
val className =
55-
StringBuilder(DEVSUPPORT_IMPL_PACKAGE)
56-
.append(".")
57-
.append(DEVSUPPORT_IMPL_CLASS)
58-
.toString()
52+
// @IgnoreStringLiterals annotation is used to enable ProGuard to strip out the
53+
// BridgeDevSupportManager class
54+
val className = "com.facebook.react.devsupport.BridgeDevSupportManager"
5955
val devSupportManagerClass = Class.forName(className)
6056
val constructor =
6157
devSupportManagerClass.getConstructor(
@@ -119,9 +115,4 @@ internal class DefaultDevSupportManagerFactory : DevSupportManagerFactory {
119115
} else {
120116
ReleaseDevSupportManager()
121117
}
122-
123-
private companion object {
124-
private const val DEVSUPPORT_IMPL_PACKAGE = "com.facebook.react.devsupport"
125-
private const val DEVSUPPORT_IMPL_CLASS = "BridgeDevSupportManager"
126-
}
127118
}

0 commit comments

Comments
 (0)