Android Tutorial
Software Setup and Configuration
Android Studio
File Structure
Components
Core Topics
Layout
View
Button
Intent and Intent Filters
Toast
RecyclerView
Fragments
Adapters
Other UI Component
Image Loading Libraries
Date and Time
Material Design
Bars
Working with Google Maps
Chart
Animation
Database
Advance Android
Jetpack
Architecture
App Publish
App Monetization
Stetho is a sophisticated debug bridge for Android applications developed by Facebook. It allows developers to access Chrome Developer Tools features natively part of the Chrome desktop browser. With Stetho, you can inspect your Android application in the same way you inspect web pages in Chrome.
When integrated, Stetho can help in:
Here's how to integrate and use Stetho in your Android application:
First, add the Stetho dependencies to your app's build.gradle
file:
implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' // If you're using OkHttp3
In your Application
class (you might need to create one if you haven't already), initialize Stetho in the onCreate
method:
import android.app.Application import com.facebook.stetho.Stetho class MyApplication : Application() { override fun onCreate() { super.onCreate() if (BuildConfig.DEBUG) { Stetho.initializeWithDefaults(this) } } }
Note: It's recommended to initialize Stetho only for debug builds to prevent it from being active in release builds.
If you're using OkHttp for network requests, you can add Stetho's interceptor to inspect network traffic:
val client = OkHttpClient.Builder() .addNetworkInterceptor(StethoInterceptor()) .build()
chrome://inspect
.After following these steps, the Chrome Developer Tools window will open, and you can select the "Resources" tab to view the app's SQLite databases, shared preferences, and more.
Stetho has more features and extensions, like integration with the stetho-js-rhino
for JavaScript inspection.
Stetho might not be actively maintained in the future, considering its last updates and the development speed of Android. Always check the library's GitHub page or other documentation for the most recent information.
There are alternatives to Stetho like Flipper by Facebook which offers similar features and more. Always explore other tools to find what best fits your needs.
Stetho setup and configuration in Android:
implementation 'com.facebook.stetho:stetho:1.5.1' implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1' // For OkHttp integrationCode (Kotlin - Application class):
import com.facebook.stetho.Stetho class MyApplication : Application() { override fun onCreate() { super.onCreate() Stetho.initializeWithDefaults(this) } }
Debugging SQLite databases with Stetho in Android:
import com.facebook.stetho.Stetho import com.facebook.stetho.inspector.database.DatabaseFilesProvider import com.facebook.stetho.inspector.database.DatabaseFilesProviderFactory class MyApplication : Application() { override fun onCreate() { super.onCreate() Stetho.initialize( Stetho.newInitializerBuilder(this) .enableDumpapp(Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this)) .addDatabaseDriver(createDatabaseDriver()) .build() ) } private fun createDatabaseDriver(): DatabaseFilesProvider { return DatabaseFilesProviderFactory(this).create() } }
Debugging JavaScript in WebView with Stetho:
import com.facebook.stetho.Stetho class MyActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Stetho.initializeWithDefaults(this) setContentView(R.layout.activity_main) val webView = findViewById<WebView>(R.id.webView) webView.settings.setJavaScriptEnabled(true) webView.settings.setDomStorageEnabled(true) Stetho.initializeWithDefaults(this) } }
Setting up Stetho for Android in Kotlin:
import com.facebook.stetho.Stetho class MyApplication : Application() { override fun onCreate() { super.onCreate() Stetho.initializeWithDefaults(this) } }