Skip to content

feat(android): publish release no-op artifact to strip all library code from production builds #16

Description

@imsankalp

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

  1. Create android-no-op/ module mirroring the public API with empty method bodies
  2. Configure as a separate library module in android-no-op/build.gradle
  3. Update autolink config to expose both modules
  4. Update docs with the debugImplementation / releaseImplementation pattern
  5. Update Expo plugin to also patch android/app/build.gradle

Acceptance criteria

  • android-no-op/ module created with stub implementations of all public API classes
  • No-op module has zero runtime dependencies beyond react-android
  • Host app example updated to use debugImplementation / releaseImplementation
  • Release APK verified with apkanalyzer: no NetworkToolsInterceptor or NetworkRequestStorage classes present
  • README updated with the split-dependency pattern

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions