Chrome:inspect查看android数据库常用的几种配置方法、chrome://inspect调试工具离线包

目录

前言

Realm配置和Stetho配置

Stetho在Chrome上直接调试android应用数据库&Okhttp网络请求

Chrome调试工具离线包 操作步骤

步骤:

总结:


 

 

前言

android比较常用的数据库框架分别是:greendao、ormlite、realm,对于这三种数据库的优缺点,既然你要使用了,就说明你有一定的了解,在这里就不介绍了!如果需要可自行google搜索即可。接下来主要说一下如何查看及配置数据库。

 

Realm配置和Stetho配置

 

Realm官方文档:https://realm.io/docs/java/latest/

 

一、1.引入Realm:在你的项目build.gradle文件下配置:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath "io.realm:realm-gradle-plugin:5.1.0"
//添加这一行

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

 

2.在你app的build.gradle中:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
二、1.引入stetho

在你项目的build.gradle中:

repositories {
    maven {
        url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
    }
}

在你app的build.gradle中:

    implementation 'com.facebook.stetho:stetho:1.5.0'
    implementation 'com.uphyca:stetho_realm:2.1.0'
stetho_realm的github地址:https://github.com/uPhyca/stetho-realm

 

三、项目中配置:

1.创建MyApplication

package com.example.administrator.myapplication;

import android.app.Application;

import com.facebook.stetho.Stetho;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;

import io.realm.Realm;
import io.realm.RealmConfiguration;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

// Initialize Realm (just once per application)
        Realm.init(this);


        RealmConfiguration config = new RealmConfiguration.Builder()
                .name("test.realm") //文件名
                .schemaVersion(3) //版本号
                .migration(new CustomMigration())
                .build();
        Realm.setDefaultConfiguration(config);
        Stetho.initialize(
                Stetho.newInitializerBuilder(this)
                        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
                        .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
                        .build());
    }
}

 

RealmConfiguration支持的方法:

  1. Builder.name : 指定数据库的名称。如不指定默认名为default。

  2. Builder.schemaVersion : 指定数据库的版本号。

  3. Builder.encryptionKey : 指定数据库的密钥。

  4. Builder.migration : 指定迁移操作的迁移类。

  5. Builder.deleteRealmIfMigrationNeeded : 声明版本冲突时自动删除原数据库。

  6. Builder.inMemory : 声明数据库只在内存中持久化。

  7. build : 完成配置构建。

  8. 详细讲解请看官网:https://realm.io/docs/java/latest/


 

Stetho在Chrome上直接调试android应用数据库&Okhttp网络请求

 

Stetho是FaceBook开源的一个android插件项目,使用它可以在Chrome浏览器上直接进行网络和数据库的调试。

Stetho的github地址:https://github.com/facebook/stetho

Stetho的官网地址:http://facebook.github.io/stetho/

 

步奏:

1.引入Stetho

 implementation'com.facebook.stetho:stetho:1.5.0'
 implementation'com.facebook.stetho:stetho-okhttp3:1.5.0'

 

2.初始化Stetho

public class MyApplication extends Application {
 @Override 
public void onCreate() { 
super.onCreate(); 
Stetho.initializeWithDefaults(this);
 } 
}

 

Enable network inspection

If you are using the popular OkHttp library at the 3.x release, you can use the Interceptors system to automatically hook into your existing stack. This is currently the simplest and most straightforward way to enable network inspection:

new OkHttpClient.Builder()
    .addNetworkInterceptor(new StethoInterceptor())
    .build()

 


 

为什么要Chrome调试工具离线包???请查看: https://www.cnblogs.com/hjblog/p/9078147.html

 

Chrome调试工具离线包 操作步骤

 

步骤:

 

1.chrome:inspect 离线调试工具包 下载后解压,得到的就是离线开发者工具包,如下图:

 

chrome

 

2. chrome地址栏输入chrome://appcache-internals,查看chrome离线包应该存放的路径,如下图 :

 

threefold

 

3.关闭chrome, 将第1步得到的3个文件夹复制到第2步显示的路径下。选择全部覆盖!再次打开chrome://appcache-internals页面应该一项对应您的版本。如果是空白,就是覆盖的路径不对。 如下图是正确显示。

 

second

 

4. 重新打开chrome,inspect调试就出来内容了

 

four

 

总结:

以上所有操作都执行三步骤:

  1. builder引入依赖包

  2. MyApplication初始化一下

  3. 运行App, 打开Chrome输入chrome://inspect/#devices(别忘了用数据线把手机和电脑连起来哦)

 

到此结束!!!

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值