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

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查看成功界面;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值