Guppy is a visual logger for both devs and testers alike that allows you to see and manage details about what network calls have been made in your current application session.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
implementation 'com.github.johnsonandjohnson:Guppy-Android:1.0.0'
Square's OkHTTP already has a way for developers to log network requests as they happen.
- Guppy is an implementation of OkHTTP Logging Interceptor
GuppyInterceptor.kt
andGuppyActivity.kt
are separate with the idea in mind that we can support and build more Interceptors in the future.- OkHTTP is the only supported network library in this first version.
- Adding a
GuppyInterceptor.kt
to your OkHTTPClient instance will enable Guppy logging to a SQLite database. - The network logs can be viewed in the Shake UI, which uses the database.
- You can enable the Shake UI in your app by implementing
ShakeAction.kt
in your own BaseActivity, or extendingGuppyActivity.kt
.
- Since a Shake Gesture requires hooks into the Activity lifecycle, in your app's BaseActivity (or, any
activity that you are making network requests you wish to inspect), you may extend this
GuppyActivity.kt
class.
class BaseActivity : GuppyActivity() {
//...
}
- Alternatively, if you would prefer to implement this yourself, Guppy exposes a
ShakeAction.kt
interface which you can implement in your own Activity.
interface ShakeAction {
fun setSensors()
fun onShakeReceived(dialogFragment: GuppyDialogFragment?)
fun buildGuppyDialogFragment(): GuppyDialogFragment?
fun register()
fun unregister()
fun getGuppyData(): List<GuppyData>
}
In your instance of OkHTTP, Add the GuppyInterceptor
class as an Interceptor.
@Singleton
@Provides
fun providesOkClient(application: Application) : OkHttpClient {
val okHttpBuilder: OkHttpClient.Builder = OkHttpClient.Builder()
//...
okHttpBuilder.addNetworkInterceptor(GuppyInterceptor())
return okHttpBuilder.build()
}
Unfortunately there is no shortcut for "Shake Gesture". In the Android Emulator,
- Click on the overflow menu (three dots)
- Click Virtual Sensors
- Select the "Move" radio button
- Rapidly move the
X
orY
sliders back and forth.
You could also tap on shortcut on main menu or just use any physical device and shake it :)
- Android Studio 3.5+
- minSDK = 21
- targetSDK = 28
For now, before we host this in jcenter, import the contained guppy
module into your project via Android Studio 3.5 or greater.
- Chris Corrado, ccorrad@its.jnj.com
- Yakun Li, yli276@its.jnj.com