Problem
Even after fixing NETWORK_TOOLS_ENABLED in build.gradle and wrapping MainApplication with if (BuildConfig.DEBUG), all library .class files — NetworkToolsInterceptor, NetworkRequestStorage, NetworkToolsEventEmitter, etc. — are still compiled into the release APK. They just happen to be dormant.
For a debug-only tool this is undesirable:
- Increases APK size
- Security audits flag unused network interception code in production binaries
- Violates the principle that debug tooling leaves zero footprint in production
Proposed solution — LeakCanary pattern
Publish two Android artifacts:
| Artifact |
Purpose |
react-native-network-tools |
Full implementation — used in debug builds |
react-native-network-tools-no-op |
Stub implementations — used in release builds |
The no-op artifact contains hollow stubs with identical public API surfaces but no actual logic:
// no-op NetworkToolsManager.kt
object NetworkToolsManager {
fun addInterceptor(builder: OkHttpClient.Builder) = builder // no-op
fun getInterceptor(): NetworkToolsInterceptor? = null
}
In the host app's android/app/build.gradle:
dependencies {
debugImplementation project(':react-native-network-tools')
releaseImplementation project(':react-native-network-tools-no-op')
}
Implementation plan
- Create
android-no-op/ module mirroring the public API with empty method bodies
- Configure as a separate library module in
android-no-op/build.gradle
- Update autolink config to expose both modules
- Update docs with the
debugImplementation / releaseImplementation pattern
- Update Expo plugin to also patch
android/app/build.gradle
Acceptance criteria
References
Problem
Even after fixing
NETWORK_TOOLS_ENABLEDinbuild.gradleand wrappingMainApplicationwithif (BuildConfig.DEBUG), all library.classfiles —NetworkToolsInterceptor,NetworkRequestStorage,NetworkToolsEventEmitter, etc. — are still compiled into the release APK. They just happen to be dormant.For a debug-only tool this is undesirable:
Proposed solution — LeakCanary pattern
Publish two Android artifacts:
react-native-network-toolsreact-native-network-tools-no-opThe no-op artifact contains hollow stubs with identical public API surfaces but no actual logic:
In the host app's
android/app/build.gradle:Implementation plan
android-no-op/module mirroring the public API with empty method bodiesandroid-no-op/build.gradledebugImplementation/releaseImplementationpatternandroid/app/build.gradleAcceptance criteria
android-no-op/module created with stub implementations of all public API classesreact-androiddebugImplementation/releaseImplementationapkanalyzer: noNetworkToolsInterceptororNetworkRequestStorageclasses presentReferences
apkanalyzer dex packages --defined-only app-release.apk