Android接入指南
| DoKit | 最新版本 | 描述 |
|---|---|---|
| 支持Androidx | 3.1.5 | 从v3.1.0版本开始支持androidx |
| 支持android support | 3.0.6 | 3.0.6版本对应3.1.5的功能,后期support将会不定期更新,主要还是看社区的反馈,请大家尽快升级和适配Androidx |
1. Gradle 依赖
1. dependencies {
2. …
3. debugImplementation 'com.didichuxing.doraemonkit:doraemonkit:3.1.5'
4. releaseImplementation 'com.didichuxing.doraemonkit:doraemonkit-no-op:3.1.5'
5. …
6. }
滴滴内部业务:
滴滴内部业务线接入请将
1. debugImplementation 'com.didichuxing.doraemonkit:doraemonkit:3.1.5'
替换为
1. debugImplementation 'com.didichuxing.doraemonkit:doraemonkit-rpc:3.1.5'
注意: 假如你无法通过 jcenter 下载到依赖库并报了以下的错误
1. ERROR: Failed to resolve: com.didichuxing.doraemonkit:doraemonkit:3.1.5
建议你可以尝试挂载VPN或通过命令行重试(以Mac系统为例 项目根目录下)
1. ./gradlew clean assembleDebug
最新版本参见这里。
注意:
安卓版本DoKit从3.1.0版本开始全面拥抱Androidx,假如你的项目还没有升级到androidx你可以选择依赖3.0.2版本 安卓版DoKit从3.0.2版本开始将逐渐放弃对Android Support版本的支持,请大家全面拥抱androidx吧
DoraemonKit目前已支持Weex工具,包括
- Console 日志查看
- Storage 缓存查看
- 容器信息
- DevTool
如果有需要支持Weex的需求可以直接添加下面依赖
1. dependencies {
2. …
3. debugImplementation 'com.didichuxing.doraemonkit:doraemonkit-weex:3.1.5'
4. …
5. }
如果有需要集成 LeakCanary 的需求可以直接添加下面依赖
1. dependencies {
2. …
3. debugImplementation 'com.didichuxing.doraemonkit:doraemonkit-leakcanary:3.1.5'
4. …
5. }
LeakCanary 已经在 doraemonkit 中动态集成,不需要自己再进行手动集成,只需要添加上面的依赖即可。
2. 初始化
在 App 启动的时候进行初始化。
1. @Override
2. public void onCreate() {
4. DoraemonKit.install(application,null,"pId");
6. }
滴滴内部业务
1. @Override
2. public void onCreate() {
4. DoraemonKitRpc.install(application,null,"pId")
6. }
3. 流量监控以及其他AOP功能(可选)
AOP包括以下几个功能: 1)百度、腾讯、高德地图的经纬度模拟 2)UrlConnection、Okhttp 抓包以及后续的接口hook功能 3)App 启动耗时统计 4)慢函数 5)大图
在项目的 build.gradle 中添加 classpath。
1. buildscript {
2. dependencies {
3. …
4. classpath 'com.didichuxing.doraemonkit:doraemonkit-plugin:3.1.5'
5. …
6. }
7. }
在 app 的 build.gradle 中添加 plugin。
1. apply plugin: 'com.didi.dokit'
插件配置选项: 添加到app module 的build.gradle文件下 与android {}处于同一级
1. dokitExt {
2. //dokit 插件开关
3. dokitPluginSwitch true
4. //通用设置
5. comm {
6. //地图经纬度开关
7. gpsSwitch true
8. //网络开关
9. networkSwitch true
10. //大图开关
11. bigImgSwitch true
12. }
14. slowMethod {
15. //0:默认模式 打印函数调用栈 需添加指定入口 默认为application onCreate 和attachBaseContext
16. //1:普通模式 运行时打印某个函数的耗时 全局业务代码函数插入
17. strategy 0
18. //函数功能开关
19. methodSwitch true
21. //调用栈模式配置
22. stackMethod {
23. //默认值为 5ms 小于该值的函数在调用栈中不显示
24. thresholdTime 10
25. //调用栈函数入口
26. enterMethods = ["com.didichuxing.doraemondemo.MainDebugActivity.test1"]
27. }
28. //普通模式配置
29. normalMethod {
30. //默认值为 500ms 小于该值的函数在运行时不会在控制台中被打印
31. thresholdTime 500
32. //需要针对函数插装的包名
33. packageNames = ["com.didichuxing.doraemondemo"]
34. //不需要针对函数插装的包名&类名
35. methodBlacklist = ["com.didichuxing.doraemondemo.dokit"]
36. }
37. }
38. }
4. 自定义功能组件(可选)
自定义组件需要实现 IKit 接口,该接口对应哆啦A梦功能面板中的组件。
以代驾乘客端为例,实现环境切换组件如下。
1. public class EnvSwitchKit extends AbstractKit {
2. @Override
3. public int getCategory() {
4. return Category.BIZ;
5. }
7. @Override
8. public int getName() {
9. return R.string.bh_env_switch;
10. }
12. @Override
13. public int getIcon() {
14. return R.drawable.bh_roadbit;
15. }
17. @Override
18. public void onClick(Context context) {
19. DebugService service = ServiceManager.getInstance().getService(context, DebugService.class);
20. PageManager.getInstance().startFragment(service.getContainer(), EnvSwitchFragment.class);
21. }
23. @Override
24. public void onAppInit(Context context) {
26. }
27. }
在初始化的时候注册自定义组件。
1. @Override
2. public void onCreate() {
3. kits.add(new EnvSwitchKit());
4. DoraemonKit.install(application, kits);
5. …
6. }
DoraemonKit入口api
1. object DoraemonKit {
2. //不需要productId
3. @JvmStatic
4. fun install(app: Application) {
5. }
7. //需要productId
8. @JvmStatic
9. fun install(app: Application, productId: String) {
10. }
12. //用户自定义用户专区分组
13. @JvmStatic
14. fun install(app: Application, mapKits: LinkedHashMap<String, MutableList<AbstractKit>>, productId: String) {
15. }
17. //默认用户专区分组
18. @JvmStatic
19. fun install(app: Application, listKits: MutableList<AbstractKit>, productId: String) {
20. }
22. /**
23. * @param app
24. * @param mapKits 自定义kits 根据用户传进来的分组 建议优先选择mapKits 两者都传的话会选择mapKits
25. * @param listKits 自定义kits 兼容原先老的api
26. * @param productId Dokit平台端申请的productId
27. */
28. @JvmStatic
29. private fun install(app: Application, mapKits: LinkedHashMap<String, MutableList<AbstractKit>>? = linkedMapOf(), listKits: MutableList<AbstractKit>? = mutableListOf(), productId: String? = "") {
31. }
33. //h5任意门回调
34. @JvmStatic
35. fun setWebDoorCallback(callback: WebDoorManager.WebDoorCallback?) {
36. }
38. //显示mainIcon
39. @JvmStatic
40. fun show() {
41. }
43. //隐藏mainIcon
44. @JvmStatic
45. fun hide() {
46. }
48. /**
49. * 直接显示工具面板页面
50. */
51. @JvmStatic
52. fun showToolPanel() {
53. }
55. /**
56. * 直接隐藏工具面板
57. */
58. @JvmStatic
59. fun hideToolPanel() {
60. }
64. /**
65. * 禁用app信息上传开关,该上传信息只为做DoKit接入量的统计,如果用户需要保护app隐私,可调用该方法进行禁用
66. */
67. @JvmStatic
68. fun disableUpload() {
69. }
71. @JvmStatic
72. val isShow: Boolean
73. get() = false
75. @JvmStatic
76. fun setDebug(debug: Boolean) {
77. }
79. /**
80. * 是否显示主入口icon
81. */
82. @JvmStatic
83. fun setAwaysShowMainIcon(awaysShow: Boolean) {
84. }
85. }
5. FAQ
参考这里
