Facebook 调试工具Stetho配置入门

简介: I decided to spend a few hours on Stetho.Stetho is a sophisticated debug bridge for Android applications.

I decided to spend a few hours on Stetho.
Stetho is a sophisticated debug bridge for Android applications.

How to enable it
It is very simple to enable Stetho.
Just add these lines to your build.gradle:


dependencies {
    // Stetho core
    compile 'com.facebook.stetho:stetho:1.1.1' //If you want to add a network helper compile 'com.facebook.stetho:stetho-okhttp:1.1.1' }

Then in your Application you can enable the tool just adding: 

Stetho.initialize(
                    Stetho.newInitializerBuilder(this) .enableDumpapp( Stetho.defaultDumperPluginsProvider(this)) .enableWebKitInspector( Stetho.defaultInspectorModulesProvider(this)) .build());

In my simple application, I have a network call with okhttp-client , a simple value in the shared preferences, and a small db with one table.
Now the last step: Run the application and just open Chrome on your pc (where the device is plugged). 
In your chrome just navigate on chrome://inspect 

As you can see in the image you can see 2 apps running in my device (I love Nexus4 for this kind of tests....)

  • Chrome
  • My Stetho Test App

How can I use it
Here you can open a magical world...clicking the inspect link.

First of all you can see the elements tab.


Here you can navigate in the elements inside your Activity......
Here a first surprise...clicking on the entry on the tab, the element is highlighted on the device !
 
The network tab. 
If you work with the Chrome Developer Tools, you know it very well. Here you can see the network calls with their data.
In my app I do a simple call with okhttp

  OkHttpClient client = new OkHttpClient(); client.networkInterceptors().add(new StethoInterceptor()); Request request = new Request.Builder() .url("https://google.com") .build(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { //do something } @Override public void onResponse(Response response) throws IOException { //do something } });

Here the tab:

The Resources tab.
In my sample app I am setting a simple value in the SharedPreferences.

 SharedPreferences.Editor editor = getSharedPreferences("TEST", MODE_PRIVATE).edit(); editor.putString("name", "Paolo"); editor.putInt("idName", 12); editor.commit();

You can check this value in the navigating in the Local Storage entry.

Also I use a simple SQLiteOpenHelper to manage a very small database with just a table.

private static final String CREATE_DATABASE = "CREATE TABLE " + TBL_USR + " ( " + TBL_USR_CLMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " + TBL_USR_CLMN_NAME + " TEXT NOT NULL, " + TBL_USR_CLMN_SURNAME + " TEXT NOT NULL, " + TBL_USR_CLMN_CODE + " INTEGER NOT NULL DEFAULT 0 " + ")"; @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_DATABASE); db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO1','ROSSI1', 233432 )"); db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO2','ROSSI2', 103213 )"); db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO3','ROSSI3', 5454331 )"); db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO4','ROSSI4', 5454444 )"); db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO5','ROSSI5', 1231232 )"); db.execSQL("INSERT INTO " + TBL_USR + " " + "("+ TBL_USR_CLMN_NAME +" , " + TBL_USR_CLMN_SURNAME +" , " + TBL_USR_CLMN_CODE +")" + " VALUES('PAOLO6','ROSSI6', 4443343 )"); }

You can navigate on the data on the WebSQL entry.

And you can run queries on your db...(!)

Of course it is only a first glance at this tool but it is enough to check the power of this debug tool. 

 

转自:http://gmariotti.blogspot.it/2015/07/a-first-glance-at-stetho-tool.html

目录
相关文章
|
数据库 Android开发 Web App开发
|
机器学习/深度学习 算法 决策智能
【重磅开源】Facebook开源 Nevergrad:一种用于无梯度优化的开源工具
【重磅开源】Facebook开源 Nevergrad:一种用于无梯度优化的开源工具
251 0
|
缓存 数据可视化 测试技术
开源多年后,Facebook这个调试工具,再登Github热门榜
让许多工程师合作开发大型应用大多会面临一个挑战,通常没有一个人知道每个模块是如何工作的,这种技能会让开发新功能、调查Bug或优化性能变得困难,为了解决这个问题,Facebook创建并开源了Flipper,一个可扩展的跨平台的调试工具,用来调试 iOS 和 Android 应用。近日又双叒登上了Github热榜。
|
前端开发 JavaScript 测试技术
Facebook 开源可扩展文本编辑器 Lexical
Meta(原 Facebook)近日开源可扩展文本编辑器 Lexical,源代码托管在 GitHub 上采用 MIT 许可证。
573 0
Facebook 开源可扩展文本编辑器 Lexical
|
XML jenkins Java
Facebook开源静态代码分析工具Infer介绍
Infer是Facebook公司的一个开源的静态分析工具。Infer 可以分析 Objective-C, Java 或者 C 代码,用于发现潜在的问题。其作用类似于sonar和fortify。Infer更倾向于发现代码中的空指针异常、资源泄露以及内存泄漏的问题。
Facebook开源静态代码分析工具Infer介绍
|
机器学习/深度学习 人工智能 文字识别
图神经网络版本的PyTorch来了,Facebook开源GTN框架,还可对图自动微分
近日,Facebook的AI研究院发表了一篇论文「DIFFERENTIABLE WEIGHTED FINITE-STATE TRANSDUCERS」,开源了用于图网络建模的GTN框架,操作类似于PyTorch这种传统的框架,也可以进行自动微分等操作,大大提高了对图模型建模的效率。
391 0
图神经网络版本的PyTorch来了,Facebook开源GTN框架,还可对图自动微分
|
移动开发 Java 程序员
Facebook 将神奇动画引擎 Pop 开源了!
Facebook 2月发布的新闻类应用Paper,因为其灵动的用户界面和交互,成为近来最令人眼前一亮的移动产品之一。 而这个产品的背后是2011年Facebook收购的Push Pop Press,创始人是分别在Apple任设计师和工程师的Mike Matas与Kimon Tsinteris。他们的合作者还有传奇人物Bret Victor。他们为美国前副总统Al Gore开发的电子书Our Choice当时就曾技惊四座。
371 0
Facebook 将神奇动画引擎 Pop 开源了!
|
PHP C语言 开发者
Facebook 发布开源编程语言 Hack
Facebook周四发布一款名为“Hack”的全新编程语言,并声称该语言将能使代码的编写和测试更加高效快速。Facebook已在公司内部使用该语言超过一年时间,现在将以开源的形式将其正式发布。
464 0
Facebook 发布开源编程语言 Hack
|
存储 安全 算法
Conceal —— Facebook推出的android数据加密的开源APIandroid数据加密的开源API
现如今很多的智能手机,都支持把应用安装到SD卡中,这会帮用户节省很多空间,但是许多黑客也会利用这一点窃取用户的隐私。一般情况下,应用都有SD卡的读写权限,当然他也可以读取到其他应用,存储在SD卡上的数据。这意味着如果你安装了恶意的应用,他就可以轻易的获取SD卡上的所有数据。
420 0
Conceal —— Facebook推出的android数据加密的开源APIandroid数据加密的开源API
|
安全 前端开发 API
KVOController:facebook 开源的 KVO(Key-value Observing)工具
KVOController 是一个简单安全的 KVO(Key-value Observing,键-值 观察)工具,用于 iOS 和 OS X 应用开发中,开源自 facebook。
301 0