Skip to content

Integrating Pluto 1.x.x

Prateek Srivastava edited this page Feb 14, 2022 · 2 revisions

Add Gradle Dependencies

Pluto is distributed through mavenCentral. To use it, you need to add the following Gradle dependency to your build.gradle file of you android app module.

Note: add both the pluto and the pluto-no-op variant to isolate Pluto from release builds.

dependencies {
  debugImplementation 'com.mocklets:pluto:1.1.3'
  releaseImplementation'com.mocklets:pluto-no-op:1.1.3'
}

Intialize Pluto

Now to start using Pluto, intialize Pluto SDK from you application class by passing context to it.

Pluto.initialize(context)

Add Pluto interceptor

To debug HTTP requests/responses, plug the PlutoInterceptor in your OkHttp Client Builder

val client = OkHttpClient.Builder()
    .addInterceptor(PlutoInterceptor())
    .build()

Set Global Exception Handler

To intercept uncaught exceptions in your app, attach UncaughtExceptionHandler to Pluto

Pluto.setExceptionHandler { thread, throwable ->
    Log.d("Exception", "uncaught exception handled on thread: " + thread.name, throwable)
}

Listen to ANRs

Pluto can capture and store potential ANRs occurring in the app. You can also listen to these ANRs and report these to any Crash reporting tools like Firebase Crashlytics, Bugsnag, etc.

Pluto.setANRListener(object: ANRListener {
    override fun onAppNotResponding(exception: ANRException) {
        exception.printStackTrace()
        PlutoLog.e("ANR", exception.threadStateMap)
    }
})

Add Pluto Logs

Pluto allows you to log and persist the user journey through the app, and help debug them without any need to connect to Logcat.

PlutoLog.event("analytics", eventName, HashMap(attributes))
PlutoLog.d("debug_log", "button clicked")
PlutoLog.e("error_log", "api call falied with http_status 400")
PlutoLog.w("warning_log", "warning log")
PlutoLog.i("info_log", "api call completed")

But if you are connected to Logcat, PlutoLogs behave similar to Log class, with an improvement to tag the method and file name also. In Logcat, PlutoLogs will look like the following.

D/onClick(MainActivity.kt:40) | debug_log: button clicked
E/onFailure(NetworkManager.kt:17) | error_log: api call falied with http_status 400

Set App Properties

Pluto allows storing information like App status(like app configurations), User properties(like email, profile) and Device fingerprint(like IMEI).

This data can later be accessed via Pluto debug UI. This method can be called multiple times and it will keep on appending the data.

Pluto.setAppProperties(hashMapOf(
    "User id" to "2whdue-dn4f-3hr-dfhrhs",
    "User email" to "john.smith@gmail.com"
))

🎉 You are all done!

Now re-build and run your app, you will receive a notification from Pluto, use it to access Pluto UI.