Skip to content

fix(plugin): wrap setCustomClientBuilder in BuildConfig.DEBUG guard#21

Merged
imsankalp merged 2 commits into
mainfrom
fix/expo-plugin-debug-guard
May 20, 2026
Merged

fix(plugin): wrap setCustomClientBuilder in BuildConfig.DEBUG guard#21
imsankalp merged 2 commits into
mainfrom
fix/expo-plugin-debug-guard

Conversation

@imsankalp

@imsankalp imsankalp commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Both KOTLIN_SNIPPET and JAVA_SNIPPET in plugin/src/index.js now wrap the setCustomClientBuilder call in if (BuildConfig.DEBUG) { ... }
  • Idempotency check is unchanged — it still detects already-patched files correctly via NetworkToolsManager.addInterceptor(builder), which remains present inside the guard
  • Tests expanded from 2 to 8 (Kotlin + Java each get: guard presence, guard ordering, idempotency, null-on-missing-onCreate)

Before vs after (Kotlin)

Before — interceptor registered unconditionally in every build:

override fun onCreate() {
    super.onCreate()

    NetworkingModule.setCustomClientBuilder(   // runs in production ❌
        object : NetworkingModule.CustomClientBuilder {
            override fun apply(builder: OkHttpClient.Builder) {
                NetworkToolsManager.addInterceptor(builder)
            }
        }
    )
}

After — interceptor only registered in debug builds:

override fun onCreate() {
    super.onCreate()

    if (BuildConfig.DEBUG) {                   // guarded ✅
        NetworkingModule.setCustomClientBuilder(
            object : NetworkingModule.CustomClientBuilder {
                override fun apply(builder: OkHttpClient.Builder) {
                    NetworkToolsManager.addInterceptor(builder)
                }
            }
        )
    }
}

Test plan

  • yarn jest plugin/src/index.test.js — all 8 tests pass
  • expo prebuild on a fresh Expo app → verify generated MainApplication.kt contains if (BuildConfig.DEBUG)
  • eas build --profile production → verify interceptor not active

Related

Depends on #14 (library build.gradle fix) which must be merged first so BuildConfig.DEBUG is reliable.

Closes #15

🤖 Generated with Claude Code

imsankalp and others added 2 commits May 20, 2026 23:36
…ctivation

NETWORK_TOOLS_ENABLED was hardcoded to true in defaultConfig, meaning the
OkHttp interceptor was added to the client in every build variant including
release. Two-part fix:

1. android/build.gradle: move the flag out of defaultConfig and set it
   explicitly per buildType (true for debug, false for release).

2. example MainApplication.kt: wrap setCustomClientBuilder in a
   BuildConfig.DEBUG guard as a second line of defence, and to make the
   debug-only intent explicit.

README and SETUP_GUIDE updated to show the BuildConfig.DEBUG guard pattern
that consumers must apply in their own MainApplication.

Closes #14

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The Expo config plugin was patching MainApplication unconditionally,
causing setCustomClientBuilder to run in every EAS build profile
including production.

Both KOTLIN_SNIPPET and JAVA_SNIPPET now wrap the interceptor setup in
if (BuildConfig.DEBUG) { ... }, matching the guard pattern required in
bare RN apps (see #14).

Tests expanded from 2 to 8: guard presence, guard ordering (addInterceptor
must appear after the if), idempotency, and null return when onCreate
pattern is absent — for both Kotlin and Java.

Closes #15

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imsankalp
imsankalp merged commit 0af55af into main May 20, 2026
6 of 7 checks passed
@imsankalp
imsankalp deleted the fix/expo-plugin-debug-guard branch May 20, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(plugin): expo config plugin must wrap setCustomClientBuilder in a BuildConfig.DEBUG guard

1 participant