Android library to record the network calls through the interceptor mechanism of the http clients.

Overview

Android Snooper

Build StatuscodecovMaven CentralBCH complianceHitCount

Introduction

Android Snooper is a library which helps in debugging issues while running the applications on android devices. One of the basic features provided includes HTTP inspection, which observes all the HTTP calls made by the app. When the device is shaked, history of all the HTTP requests is presented with their responses and allows search, copy and sharing of the request/response. This library is inspired by the Network Request History feature of FLEX app for iOS.

Snooper

How to use?

Android Snooper works on the interceptor pattern which is supported by almost every HTTP client. All you need to do is initialize Android Snooper using AndroidSnooper.init(this); statement in your Application class and set an instance of SnooperInterceptor to the list of your network interceptors. As of now Snooper supports the interceptors for the following libraries:

Didn't get your HTTP client's name in the list? No worries, You can still write your own implementation by using Android Snooper's core module and let Android Snooper know about the request being made. Below is given a dummy implementation.

    AndroidSnooper androidSnooper = AndroidSnooper.getInstance();
    HttpCall httpCall = new HttpCall.Builder()
      .withUrl(httpRequest.getUrl())
      .withPayload(httpRequest.getRequestPayload())
      .withMethod(httpRequest.getMethod())
      .withResponseBody(httpResponse.getResponseBody())
      .withStatusCode(httpResponse.getRawStatusCode())
      .withStatusText(httpResponse.getStatusCode())
      .withRequestHeaders(httpRequest.getHeaders())
      .withResponseHeaders(httpResponse.getHeaders())
      .build();
    androidSnooper.record(httpCall);

The above implementation ought to be part of your custom interceptor where you will have access to the required Request and Response object to jot down the required data for Android Snooper to work properly.

Warning: Android Snooper records each and every HTTP call intercepted by it. The sole purpose of Android snooper is to help in debugging, hence only Debug or QA builds are the perfect candidates for integrating the library. Sensitive information such as Auth Tokens, Headers, etc are not supposed to be exposed and hence production apps should not integrate the library.

Integration

    repositories {
        mavenCentral()
    }

    // when using Android Snooper's core module
    compile ('com.github.jainsahab:Snooper:1.5.5@aar'){
      transitive = true
    }

    // Android Snooper library for "Spring Android Rest Template"
    compile ('com.github.jainsahab:Snooper-Spring:1.5.5@aar'){
      transitive = true
    }
    
    // Android Snooper library for "Square's Okhttp"
    compile ('com.github.jainsahab:Snooper-Okhttp:1.5.5@aar'){
      transitive = true
    }

Snapshot versions are available in Sonatype's snapshots repository.

Contributing

If you would like to contribute code to AndroidSnooper you can do so by forking the repository and create a Pull request. You can also create an Issue to report bugs or features that you want to see in AndroidSnooper library.

Attributions

This library uses:

LICENSE

Copyright (C) 2017 Prateek Jain

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Need to support Support 28

    Need to support Support 28

    Way to reproduce: Client App with the following:

    • Target SDK 28
    • Build Tools 28.03
    • Support Library (especially design), 28.0.0
    • AGP 3.3.2
    • Gradle Version 5.1.1
    • IncludeSnooper-Spring or Snooper-OKHttp, the dependency for Snooper will get pulled in by which ever you use. In our case, we have both and Snooper-Spring brought in Snooper
    • Make network call
    • Go to HttpCallListActivity
    • Tap on something to get to HttpCallActivity

    You will get an exception similar to this:

    06-03 12:39:40.824 6596-6596/com.vaa.runway.dev E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.my.package.dev, PID: 6596
        java.lang.NoSuchMethodError: No virtual method addOnTabSelectedListener(Landroid/support/design/widget/TabLayout$OnTabSelectedListener;)V in class Landroid/support/design/widget/TabLayout; or its super classes (declaration of 'android.support.design.widget.TabLayout' appears in /data/app/com.my.package.dev-1/base.apk:classes10.dex)
            at com.prateekj.snooper.networksnooper.activity.HttpCallActivity.setupUi(HttpCallActivity.java:82)
            at com.prateekj.snooper.networksnooper.activity.HttpCallActivity.onCreate(HttpCallActivity.java:69)
            at android.app.Activity.performCreate(Activity.java:6237)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
            at android.app.ActivityThread.-wrap11(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    

    It does not matter if you exclude the support group or if the hosting application pulls in design via implementation or api, it will always crash here.

    To get around this, I had to:

    • clone the repository
    • changed all support to be 28 (it is ideal as Studio will lint a host application for using a different version than the target).
    • run ./gradlew publish
    • copied the aars and referenced a local maven repository from gradle/wrapper/gradle-wrapper.properties (e.g., localSnooperLibaryRoot)
    • added the needed check sums, modified the group to avoid conflicts
    • recompile
    • It now works properly

    I also tested this out locally by changing implementation to api while keeping the support as 27, but that didn't work.

    One path I did not check was reducing the target to 27 to keep it in line with guidelines to align target + support pre-AndroidX

    opened by dannybduval 7
  • Exception with material design version

    Exception with material design version

    When my using material version 1.1.0-alpha05, the snooper library crashes with the following exception:

    Caused by: java.lang.ClassCastException: com.prateekj.snooper.networksnooper.activity.HttpCallActivity$setupUi$1 cannot be cast to com.google.android.material.tabs.TabLayout$BaseOnTabSelectedListener 09-24 11:41:47.662 11526 11526 E AndroidRuntime: at com.prateekj.snooper.networksnooper.activity.HttpCallActivity.setupUi(HttpCallActivity.kt:72) 09-24 11:41:47.662 11526 11526 E AndroidRuntime: at com.prateekj.snooper.networksnooper.activity.HttpCallActivity.onCreate(HttpCallActivity.kt:61)

    Are there plans to update the library using material version 1.1.0 or later? Looks like it's using 1.0.0 which is quite old.

    opened by retsameht01 4
  • Crash when click or swap to tab REQUEST # & HEADERS

    Crash when click or swap to tab REQUEST # & HEADERS

    When click on 2nd or 3rd tab, it's crashed. **occurred on most of the android version

    Solution: have been solved by changing following: replace following snippets- In class HttpCallActivity:

    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { ....

    by

    tabLayout.addOnTabSelectedListener(new TabLayout.BaseOnTabSelectedListener() {   ....
    

    please update this library with resolving this issue

    Thanks

    opened by glm-mawla 4
  • Crash when switching to request or header tabs

    Crash when switching to request or header tabs

    i am using androidX. java.lang.IncompatibleClassChangeError: Class 'com.prateekj.snooper.networksnooper.activity.HttpCallActivity$1' does not implement interface 'com.google.android.material.tabs.TabLayout$BaseOnTabSelectedListener' in call to 'void com.google.android.material.tabs.TabLayout$BaseOnTabSelectedListener.onTabUnselected(com.google.android.material.tabs.TabLayout$Tab)' (declaration of 'com.google.android.material.tabs.TabLayout$1' appears in base.apk) at com.google.android.material.tabs.TabLayout$1.onTabUnselected(TabLayout.java:825) at com.google.android.material.tabs.TabLayout.dispatchTabUnselected(TabLayout.java:1798) at com.google.android.material.tabs.TabLayout.selectTab(TabLayout.java:1782) at com.google.android.material.tabs.TabLayout.selectTab(TabLayout.java:1745) at com.google.android.material.tabs.TabLayout$Tab.select(TabLayout.java:2136) at com.google.android.material.tabs.TabLayout$TabView.performClick(TabLayout.java:2324) at android.view.View.performClickInternal(View.java:6585) at android.view.View.access$3100(View.java:785) at android.view.View$PerformClick.run(View.java:25921) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6861) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

    opened by bryancaray 3
  • Upgrade from 1.5.5 to 1.5.6 break project compilation

    Upgrade from 1.5.5 to 1.5.6 break project compilation

    Hello,

    I was using v1.5.5 with okhttp :

    // Android Snooper library for Okhttp
        implementation('com.github.jainsahab:Snooper-Okhttp:1.5.5@aar') {
        transitive = true
    }
    

    When I upgrade to 1.5.6, I can not run my unit tests anymore, do you have an idea of what happened ? Maybe there is a conflict in dependencies ?

    // Android Snooper library for Okhttp
        implementation('com.github.jainsahab:Snooper-Okhttp:1.5.6@aar') {
        transitive = true
    }
    

    The error appear when I run ./gradlew app:compilePrimaryDebugUnitTestKotlin :

    > Task :app:compilePrimaryDebugUnitTestKotlin FAILED
    e: /Users/benj/Desktop/XXX/XXX-android-client/app/src/test/java/com/wayzup/object/ObjectTestHelper.kt: (3, 27): Unresolved reference: lang3
    e: /Users/benj/Desktop/XXX/XXX-android-client/app/src/test/java/com/wayzup/object/ObjectTestHelper.kt: (18, 26): Unresolved reference: SerializationUtils
    e: /Users/benj/Desktop/XXX/XXX-android-client/app/src/test/java/com/wayzup/object/ObjectTestHelper.kt: (19, 28): Unresolved reference: SerializationUtils
    
    opened by ben-j69 2
  • Move writes to the DB to a background thread.

    Move writes to the DB to a background thread.

    Writes to the DB on the main thread cause animation jitter if even a few small network requests are in progress. I use this library for development builds in the application I work on (it's great by the way, thank you for making this open source), but a constant complaint from QA is that animations any kind of scrolling or dragging can become stuttered if a network request occurs at the same time.

    opened by nullptr2this 2
  • Kotlin code basic improvements

    Kotlin code basic improvements

    Hello, we are using your library so we give back some time to help improve it.

    I did a first check to fix basic warnings.

    If this PR is accepted I will dive deeply in the code by updating the kotlin version and make bigger changes/fixes.

    opened by ben-j69 1
  • Enhancement: Adding no-op dependency for all the modules

    Enhancement: Adding no-op dependency for all the modules

    @jainsahab It would be really helpful if you can add no-op dependencies for all the modules as it makes the life of consumer a whole lot easier while using this library.

    enhancement Done 
    opened by ajitsing 1
  • FileUriExposedException while sharing request/response through Intent

    FileUriExposedException while sharing request/response through Intent

    Sharing uri with "file://" scheme is not preferred from API 24 onwards, we must expose the file URI through FileProvider which will internally use "content://" scheme.

    image

    bug Done 
    opened by jainsahab 0
  • Adding headers in the share data functionality

    Adding headers in the share data functionality

    When clicking on share button, currently only request and response body is being shared. Requirement is to include headers as well in the data being shared.

    opened by harshnaraini 0
  • Infinite loader issue on Http call detail page

    Infinite loader issue on Http call detail page

    Steps to replicate. 1.) Navigate to Header tab 2.) Change the orientation of device

    Expected Behaviour Orientation should change and header tab should be visible

    Actual Behaviour Orientation is getting changed but the loader is not going away off the screen leaving the screen non-interactive.

    bug Done 
    opened by jainsahab 0
  • OkHttp SnooperInterceptor breaks Glide

    OkHttp SnooperInterceptor breaks Glide

    I found out that SnooperInterceptor prevents Glide to download images and show them properly.

    When I remove SnooperInterceptor from my OkHttpClient, Glide works fine.

    You can try it via http://via.placeholder.com/300/09f/fff.png

    SDK Version: 1.5.5@aar Android OS Version: 11 Device: Xiaomi RedMi Note 9 Pro

    opened by egemenhamutcu 0
  • because there is no current transaction.

    because there is no current transaction.

    // val snooperRepo = SnooperRepo(context) // snooperRepo.deleteAll()

    error log: because there is no current transaction.

    opened by s3hengwu 1
  • upload image error

    upload image error

    java.lang.RuntimeException:Unable to start activity ComponentInfo{com.nebula.chargemew/com.prateekj.snooper.networksnooper.activity.HttpCallListActivity}: android.database.sqlite.SQLiteBlobTooBigException: Row too big to fit into CursorWindow requiredPos=5, totalRows=6

    opened by s3hengwu 1
Releases(V1.5.6)
Owner
Prateek
Developer at @ThoughtWorks, Open source contributor to @jenkinsci, @square and @duckduckgo
Prateek
A library for debugging android databases and shared preferences - Make Debugging Great Again

Android Debug Database Android Debug Database is a powerful library for debugging databases and shared preferences in Android applications Android Deb

AMIT SHEKHAR 8.1k Dec 29, 2022
Under the Hood is a flexible and powerful Android debug view library. It uses a modular template system that can be easily extended to your needs, although coming with many useful elements built-in.

Under the Hood - Android App Debug View Library Under the Hood is a flexible and powerful Android debug view library. It uses a modular template syste

Patrick Favre-Bulle 217 Nov 25, 2022
traffic debugging library for android

TrafficMonitor About Display traffic per Activity.Observing traffic is used by TrafficStats API. OkHttp Interceptor observer is implementing. Demo Bai

Tetsuya Masuda 17 Feb 4, 2022
Cordova plugin for Android Serial USB communication (easily connect an Arduino board to an Android device).

PR-DC cordova-plugin-serialusb Cordova plugin for Android Serial USB communication. This plugin makes a connection to the external board trivial, for

PR-DC 3 May 8, 2022
Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.

Stetho Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature nat

Facebook 12.6k Jan 7, 2023
🔪Swiss-army knife for Android testing and development 🔪 ⛺

ADB Enhanced ADB-Enhanced is a Swiss-army knife for Android testing and development. A command-line interface to trigger various scenarios like screen

Ashish Bhatia 938 Dec 20, 2022
A Read-Eval-Print-Loop server for Android and SQLite

Android DebugPort Android DebugPort is a drop-in utility which allows you to write and execute code within your app's context, at runtime, and from th

Jason Feinstein 148 Nov 14, 2022
Easy android exception tracer and handler.

Introduction Lup is a small android library that can help you to tracking bug that causes application stopped working (force close). Whiting this libr

icodeu 4 Sep 29, 2022
Sources for the LiveBoot app for rooted Android devices

This is the sauce for the LiveBoot app. License Copyright © 2011-2020 Jorrit Chainfire Jongma This code is released under the GPLv3. LICENSE, COPYING.

Chainfire 131 Jan 9, 2023
android logcat

android logcat

Ji Sungbin 3 Dec 2, 2022
A local ADB shell for Android!

LADB A local ADB shell for Android! How does it work? LADB bundles an ADB server within the app libraries. Normally, this server cannot connect to the

Tyler 1.1k Jan 2, 2023
btrace(AKA RheaTrace) is a high performance Android trace tool which is based on Systrace

btrace README 中文版 btrace(AKA RheaTrace) is a high performance Android trace tool

Bytedance Inc. 1.2k Jan 4, 2023
Pluto: An on-device debugging framework for Android applications

Pluto is an on-device debugging framework for Android applications, which helps in the inspection of HTTP requests/responses, captures Crashes, and ANRs, and manipulates application data on the go.

Pluto 550 Dec 27, 2022
Android QA/Debug tools to speed up and streamline the development progress.

Android Dev Tools is a library that contains various QA/Debug tools to speed up and streamline the development progress.

Trendyol Open Source 105 Dec 5, 2022
Gradle plugin to check, if rest-controllers are used by clients and clients have suitable rest-interfaces

Verify-Feign Gradle Plugin This plugin will help you to verify all rest-clients and -controllers in a multimodule spring project. It will check, if al

null 3 May 11, 2022
Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a design pattern: proxy, delegate, interceptor.

1. AutoProxy Annotation Processing Library. Generates proxy class on top of interface/abstract class, that allows to intercept calls. Also known as a

Oleksandr 19 Nov 24, 2022
Ktorfit - a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Jens Klingenberg 637 Dec 25, 2022
KTor-Client---Android - The essence of KTor Client for network calls

KTor Client - Android This project encompasses the essence of KTor Client for ne

Mansoor Nisar 2 Jan 18, 2022
An app which displays questions from Stack Exchange from it's api. Can search questions with tags as well. Uses MVVM architecture, dependency injection, coroutines, retrofit2 for network calls

Stack Exchange app What the app does? Shows a list of trending questions from stack exchange api Can search for the desires question. Can add tags to

null 0 Apr 27, 2022