Android 引入hunter-timing监测UI主线程函数运行时耗时,Java(2)
(1)在工程的根build.gradle文件配置:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'cn.quinnchen.hunter:hunter-timing-plugin:1.2.3'
classpath 'cn.quinnchen.hunter:hunter-transform:1.2.3'
}
}
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
}
(2)在app模块的build.gradle配置:
plugins {
id 'com.android.application'
id 'hunter-timing'
}
android {
}
dependencies {
implementation 'cn.quinnchen.hunter:hunter-timing-library:1.2.3'
}
(3)上层Java代码:
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
longTimeWork();
}
private void longTimeWork() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
同时重载Application,
import android.app.Application;
import com.hunter.library.timing.BlockManager;
import com.hunter.library.timing.IBlockHandler;
import com.hunter.library.timing.impl.StacktraceBlockHandler;
public class MyApp extends Application {
private IBlockHandler customBlockManager = new StacktraceBlockHandler(50);
@Override
public void onCreate() {
super.onCreate();
BlockManager.installBlockManager(customBlockManager);
}
public IBlockHandler getCustomBlockManager() {
return customBlockManager;
}
}
写入到Androidmanifest.xml里面:
<application
android:name=".MyApp"
>
</application>
运行输出:
Android 引入hunter-debug监测代码运行时函数耗时和参数及返回值,Java(1)_zhangphil的博客-CSDN博客Android 引入hunter-debug监测代码运行时函数耗时和参数及返回值,Java(1)https://blog.csdn.net/zhangphil/article/details/130590724