Giter Site home page Giter Site logo

debugtools's Introduction

DebugTools

DebugTools是一个设计开发者支撑工具库

findViewById<TextView>(R.id.tv_name).setOnClickListener {
        //方法一
        var clazz: Class<*>? = null
        try {
            clazz = Class.forName("com.peakmain.debug.DebugToolDialogFragment")
            val target: DebugToolDialogFragment =
                clazz.getConstructor().newInstance() as DebugToolDialogFragment
            target.show(activity.getSupportFragmentManager(), "debug_tool")
        } catch (e: Exception) {
            throw RuntimeException(e)
        }
        //方法二:使用DebugToolsManager,只支持FragmentActivity
	DebugToolsManager.instance.show(this)
}

How To

  • Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
  • Step 2. Add the dependency
	dependencies {
	       implementation "com.github.Peakmain:DebugTools:+"
	}

日志捕获分享框架

日志捕获分享框架

  • App中初始化
 CrashUtils.init(this)
  • 如果对native异常进行捕获,还需要拷贝libbreakpad.aar到libs目录下

网络抓包工具

网络抓包工具

  • 网络请求添加拦截器
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(new com.peakmain.debug.log.HttpLoggingInterceptor());
一、DebugTools功能
  1. 支持查看最新接口前100条数据
  2. 支持正序和倒序排序
  3. 可查看每个接口的Header,请求参数与返回结果
  4. 支持分享给开发
二、所有Activity显示悬浮按钮点击显示网络抓包工具
fun addSuspensionView(activity: AppCompatActivity) {
    val suspensionView = SuspensionView(
        activity, com.atour.atourlife.R.drawable.ui_ic_suspension_setting,
        56f, 60f, 20f, null, 0
    )
    activity.addContentView(
        suspensionView,
        FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT
        )
    )
    suspensionView.setSuspensionViewClick {
        //方法一
        var clazz: Class<*>? = null
        try {
            clazz = Class.forName("com.peakmain.debug.DebugToolDialogFragment")
            val target: DebugToolDialogFragment =
                clazz.getConstructor().newInstance() as DebugToolDialogFragment
            target.show(activity.getSupportFragmentManager(), "debug_tool")
        } catch (e: Exception) {
            throw RuntimeException(e)
        }
        //方法二:使用DebugToolsManager,只支持FragmentActivity
	DebugToolsManager.instance.show(this)
    }
}
三、 Jenkins智能控制开关
  1. Android在项目的build.gradle(一般都是app/build.gradle),利用project.property获取属性,比如我这里属性名是IS_LOG_CONSONLE_ENABLE
def releaseLogConsoleEnable = project.property('IS_LOG_CONSONLE_ENABLE')
  1. buildTypes中通过buildConfigField方法,将属性添加BuildConfig
buildTypes {
    release {
        buildConfigField "boolean", "releaseLogConsoleEnable", releaseLogConsoleEnable
    }
    debug {
        buildConfigField "boolean", "releaseLogConsoleEnable", releaseLogConsoleEnable

    }
}
  1. 显示开关按钮的地方,添加代码开关
if(BuildConfig.releaseLogConsoleEnable) {
    addSuspensionView(this);
}

至此Android相关代码配置完成,接下来是Jenkins

  1. Jenkins添加选项设置属性为IS_LOG_CONSONLE_ENABLE
image
  1. Jenkins gradle配置代码-PIS_LOG_CONSONLE_ENABLE=$IS_LOG_CONSONLE_ENABLE
./gradlew -Dgradle.user.home=$GRADLE_HOME clean assemble$buildType -b ${WORKSPACE}/app/build.gradle -PIS_LOG_CONSONLE_ENABLE=$IS_LOG_CONSONLE_ENABLE

fps监控

fps

  • App的AndroidManifest.xml需要添加悬浮窗权限
 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
  • 开启悬浮窗权限即可

环境切换

一键网络切换

一、initEnvironmentExchangeBeanList:初始化http环境列表
fun initEnvironmentExchangeBeanList(
    environmentExchangeBeans: MutableList<EnvironmentExchangeBean>,
    selectEnvironmentCallback: ((EnvironmentExchangeBean) -> Unit)? = null,
)
  • 第一个参数environmentExchangeBeans表示http环境列表
  • 第二个参数表示选中某一个http环境的回调
二、initH5EnvironmentExchangeBeanList:初始化http环境列表
fun initH5EnvironmentExchangeBeanList(
    environmentExchangeBeans: MutableList<EnvironmentExchangeBean>,
    selectH5EnvironmentCallback: ((EnvironmentExchangeBean) -> Unit)? = null,
)
  • 第一个参数environmentExchangeBeans表示H5环境列表
  • 第二个参数表示选中某一个H5环境的回调
demo如下
    var mEnvironmentExchangeBeans: MutableList<EnvironmentExchangeBean> = ArrayList()//初始化原生环境列表
    var mH5EnvironmentExchangeBeans: MutableList<EnvironmentExchangeBean> = ArrayList()//初始化H5环境列表
    findViewById<TextView>(R.id.tv_name).setOnClickListener {
            DebugToolsManager.instance
                .initEnvironmentExchangeBeanList(mEnvironmentExchangeBeans) {
                    ToastUtils.showLong("当前选中的环境是:${it.title},url是:${it.url}")
                }.initH5EnvironmentExchangeBeanList(mH5EnvironmentExchangeBeans){
                    LogUtils.e("当前选中的H5环境是:${it.title},url是:${it.url}")
                    ToastUtils.showLong("当前选中的H5环境是:${it.title},url是:${it.url}")
                }
                .show(this)
        }
  • EnvironmentExchangeBean有三个参数:title(标题)、url(http或者H5链接)、isSelected(是否被选中)
data class EnvironmentExchangeBean(
    val title: String,
    val url: String,
    var isSelected: Boolean = false
)
  • 当http环境列表有多个环境的isSelected被设置为true,则只有第一个默认是被设置为true,其他则会被设置为false。H5环境列表也是同理。

debugtools's People

Contributors

peakmain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.