-
Notifications
You must be signed in to change notification settings - Fork 1
Android Usage
wiki de pasquale edited this page Aug 17, 2022
·
4 revisions
Your project needs to contain multiple source sets. To be precise you need main
, debug
and release
.
Create a class named InterceptorFactory
and paste this to the newly created class:
abstract class InterceptorFactory {
abstract fun create(): Interceptor
}
- Switch your project to the debug variant.
- Click on "Android" in the top left corner of the Project tab.
- Switch to "Project".
- Navigate to your module where you've just created the
InterceptorFactory
. - Right click on the module and select "New > Directory" and enter
src/debug/java/com/your/package
(ex.src/debug/java/gecko/ui
). - Right click on the module and select "New > Directory" and enter
src/release/java/com/your/package
(ex.src/debug/java/gecko/ui
). - Right click on the newly bottom-most directory created in
debug
source set and create a new classInterceptorFactoryImpl
- Paste following into the newly created file
class InterceptorFactoryDefault : InterceptorFactory() {
override fun create(): Interceptor {
return GeckoInterceptor()
}
}
Please follow debug source set's step 6)
- Switch your active variant to
release
- Switch to "Project" (as per step 3) in
debug
) - Navigate to the release source set and create a new class
InterceptorFactoryImpl
in the same exact package (!important!) - Paste following into the newly created file
class InterceptorFactoryDefault : InterceptorFactory() {
override fun create(): Interceptor {
return Interceptor { it.proceed(it.request()) }
}
}
Locate the OkHttp builder and add Gecko as the last interceptor:
OkHttpClient.Builder()
.addInterceptor(RandomInterceptor())
.addInterceptor(AnotherInterceptor())
.addInterceptor(YetAnotherInterceptor())
// more interceptors here
.addInterceptor(InterceptorFactoryDefault().create()) // <--
.build()
Run ./gradlew assemble
on your project and observe if any errors occur. Nothing? Nice! You're now all set up.
You managed to successfully implement Gecko as a Debug only library. There will be absolutely no trace of Gecko in your release builds.