利用Stetho在Chrome進行Android網絡和數據庫的調試

1.在build.gradle中添加

<pre>
dependencies {
compile 'com.facebook.stetho:stetho:1.3.1'
}
</pre>

2.在Application子類中 添加初始化的代碼到Application內,完成這一步就具備查看數據庫,查看View層級結構,使用默認dumpapp工具的能力了

<pre>

public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
//方法一
//Stetho.initializeWithDefaults(this);
//方法二
Stetho.initialize(Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
}
</pre>

3.在AndroidManifest.xml中添加 android:name=".MyApplication"

<pre>
<application
android:name=".base.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".home.HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</pre>

4.以上實現了查看數據庫和SharedPreferences

運行程序后就會發現,在chrome中的網址欄輸入:**chrome://inspect/即可看到你想看到的

5.如果需要查看網絡請求首先

<pre>
<uses-permission android:name="android.permission.INTERNET"/>
</pre>

6.剩余就是網絡請求代碼

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容