1. Stetho
使用Stetho可以轻松使用 Chrome 的 DevTools 对安卓的网络请求,view 树,数据库,SharePreference 等进行查看。免除了抓包工具对安卓设备抓包需要进行的繁琐设置等。
预览
![](https://img.haomeiwen.com/i103830/6f8a4bfd0489008e.png)
![](https://img.haomeiwen.com/i103830/23c2bbf71bad6a41.png)
使用
//stetho
dependencies {
compile 'com.facebook.stetho:stetho:1.5.0'
}
可选
dependencies {
compile 'com.facebook.stetho:stetho-okhttp3:1.5.0' //如果使用 okhttp3
compile 'com.facebook.stetho:stetho-okhttp:1.5.0' //如果使用 okhttp
compile 'com.facebook.stetho:stetho-urlconnection:1.5.0' //如果使用 urlconnection
}
添加 application 中初始化
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
添加 okhttp 拦截器: StethoInterceptor
For OkHttp 2.x
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
For OkHttp 3.x
new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
最后app跑起来,手机打开usb调试,连接到电脑。chrome 打开 chrome://inspect (国产的chrome内核浏览器也可以的),就可以开心使用了。
2. BlockCanaryEx(基于 BlockCanary)
app卡顿分析工具
使用
root build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0' //version must >= 1.5.0
classpath 'com.letv.sarrsdesktop:BlockCanaryExPlugin:0.9.9.5'
}
}
module build.gradle
apply plugin: 'blockcanaryex'
debugCompile 'com.letv.sarrsdesktop:BlockCanaryExJRT:0.9.9.4'
releaseCompile 'com.letv.sarrsdesktop:BlockCanaryExJRTNoOp:0.9.9.4'
testCompile 'com.letv.sarrsdesktop:BlockCanaryExJRTNoOp:0.9.9.4'
Basic Usage
init BlockCanaryEx before other method when your application attachBaseContext
public class TestApplication extends Application {
@Override
public void attachBaseContext(Context context) {
super.attachBaseContext(context);
boolean isInSamplerProcess = BlockCanaryEx.isInSamplerProcess(this);
if(!isInSamplerProcess) {
BlockCanaryEx.install(new Config(this));
}
if(!isInSamplerProcess) {
//your code start here
}
}
}
完成了, 现在 BlockCanaryEx 已经可以在debug模式下使用了.
最后运行一下。手机端就可以查看卡顿情况的分析了
网友评论