ChuckerTeam / chucker

🔎 An HTTP inspector for Android & OkHTTP (like Charles but on device)
Apache License 2.0
3.97k stars 351 forks source link

Custom Build Variant not working in Kotlin DSL #1288

Closed erikgunawan closed 1 month ago

erikgunawan commented 1 month ago

:writing_hand: Describe the bug

I have 3 build variants: debug, beta, release

Here are the chucker implementations:

  debugImplementation "com.github.chuckerteam.chucker:library:3.5.2"
  betaImplementation "com.github.chuckerteam.chucker:library:3.5.2"
  releaseImplementation 'com.github.chuckerteam.chucker:library-no-op:3.5.2'

And then I tried to migrate the build configuration from Groovy to Kotlin DSL, so I changed the implementations to these:

debugImplementation(libs.chucker)
  betaImplementation(libs.chucker)
  releaseImplementation(libs.chucker.no.op)

After that, when building the apps, I got this warning:

Unresolved reference: betaImplementation

I have tried some options, but none of them work

1. add("beta", libs.chucker)

2. "betaImplementation"(libs.chucker)

cortinico commented 1 month ago

"betaImplementation"(libs.chucker)

This is the correct syntax for Kotlin DSL and should work.

erikgunawan commented 1 month ago

"betaImplementation"(libs.chucker)

This is the correct syntax for Kotlin DSL and should work.

It doesn't work, Chucker notification doesn't appear.

cortinico commented 1 month ago

It doesn't work, Chucker notification doesn't appear.

Then please provide a reproducer using this template: https://github.com/cortinico/kotlin-android-template

and I'll look into it

erikgunawan commented 1 month ago

"betaImplementation"(libs.chucker)

This is the correct syntax for Kotlin DSL and should work.

Aah my bad, after checking deeply, the issue is because I'm using multi-module architecture (data, domain, app modules).

I call Chucker with the Debug checker like this:

if (BuildConfig.DEBUG) {
      okBuilder.addInterceptor(
        Builder(context)
          .collector(ChuckerCollector(context))
          .maxContentLength(250000L)
          .redactHeaders(emptySet())
          .alwaysReadResponseBody(true)
          .build()
      )
    }

In the data modules, BuildConfig.DEBUG is always returned false, so the chucker doesn't show. After removing that logic, it works well.

Thanks @cortinico