Android studio 运用Chorme 调试过程以及代码 stetho 运用

来源:互联网 发布:java多线程set redis 编辑:程序博客网 时间:2024/05/20 11:22

Android studio 运用Chorme 调试过程以及代码

第一步:导入jar包:okhttp-3.9.0.jar

      stetho-1.3.1.jar      stetho-okhttp3-1.3.1.jar      stetho-urlconnection-1.3.1.jar

第二步:然后在app的build.gradle中填入代码:

 compile 'com.facebook.stetho:stetho:1.3.1' compile 'com.facebook.stetho:stetho-okhttp3:1.3.1' compile 'com.facebook.stetho:stetho-urlconnection:1.3.1'

第三步:AndroidManifest.xml中代码

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    package="com.example.mr.myapplication">    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:roundIcon="@mipmap/ic_launcher_round"        android:supportsRtl="true"        android:theme="@style/AppTheme"        tools:replace="android:name"        android:name=".MyApplication">        <activity android:name=".login">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <activity android:name=".MainActivity"></activity>        <dependency>            <groupid>com.facebook.stetho</groupid>            <artifactid>stetho</artifactid>            <version>1.3.1</version>        </dependency>    </application></manifest>

第四步:建立类MyApplication

package com.example.mr.myapplication;import android.app.Application;import com.facebook.stetho.Stetho;import com.facebook.stetho.okhttp3.StethoInterceptor;import okhttp3.OkHttpClient;public class MyApplication extends Application {    public static OkHttpClient okHttpClient;    public void onCreate() {        super.onCreate();        //  一般使用默认初始化配置足够使用        Stetho.initializeWithDefaults(this);        // 如果需要查看网络请求相关信息(以使用okhttp3为例)        initOkHttp();    }    private void initOkHttp() {        okHttpClient =  new OkHttpClient()                .newBuilder()                .addNetworkInterceptor(new StethoInterceptor()) // 这里添加一个拦截器即可                .build();    }}

成功界面:

在Google中输入chrome://inspect在Google中输入Chrome://inspect 点击inspect查看成功界面;

原创粉丝点击