### Install DoKit via npm Source: https://github.com/didi/dokit/blob/master/Doc/miniapp_cn_guide.md Install the DoKit SDK for mini programs using npm. After installation, copy the 'dokit-miniapp' folder into your project. ```bash npm install dokit-miniapp ``` -------------------------------- ### WeChat Mini Program: NPM Installation and Component Import Source: https://context7.com/didi/dokit/llms.txt Install the DoKit Mini Program SDK via NPM and import the component into your pages. Use the projectId parameter to connect to the dokit.cn platform for features like data mocking. ```bash # 安装 DoKit 小程序 SDK npm install dokit-miniapp # 将 node_modules/dokit-miniapp 拷贝到项目目录(微信小程序暂不支持直接引用 node_modules) cp -r node_modules/dokit-miniapp src/components/ ``` -------------------------------- ### Configure DoraemonKit with Custom Plugin Source: https://github.com/didi/dokit/wiki/Home This configuration method demonstrates how to integrate a custom plugin ('环境切换') and configure the H5 door functionality within the application's setup. It ensures DoraemonKit is installed with custom modules. ```objective-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef DEBUG [self configDoraemonKit]; #endif } //配置Doraemon工具集 - (void)configDoraemonKit{ [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"qiehuang" desc:@"用于app内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"]; [[DoraemonManager shareInstance] addH5DoorBlock:^(NSString *h5Url) { [APP_INTERACOTR.rootNav openURL:@"KDSJ://KDWebViewController" withQuery:@{@"urlString":h5Url}]; }]; [[DoraemonManager shareInstance] install]; } ``` -------------------------------- ### Initialize DoraemonKit in Swift Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md Integrate DoraemonKit in a Swift project by importing the framework and calling `install()` on `DoraemonManager` within the `DEBUG` preprocessor directive during application launch. ```swift import UIKit #if DEBUG import DoraemonKit #endif @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. #if DEBUG DoraemonManager.shareInstance().install() #endif return true } } ``` -------------------------------- ### iOS Objective-C Initialization for DoKit Source: https://context7.com/didi/dokit/llms.txt Initialize DoKit in your AppDelegate's `application:didFinishLaunchingWithOptions:` method. This ensures DoKit is only active in Debug builds. You can use the default installation or specify a starting position for the floating ball. ```objective-c #ifdef DEBUG #import #endif - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef DEBUG // 默认启动,悬浮球出现在左上角 [[DoraemonManager shareInstance] install]; // 或:指定初始位置,避免遮挡关键区域 // [[DoraemonManager shareInstance] installWithStartingPosition:CGPointMake(66, 66)]; #endif return YES; } ``` -------------------------------- ### Initialize DoraemonKit in App Delegate Source: https://github.com/didi/dokit/wiki/Home Integrate DoraemonKit into your application by calling the install method in your application's launch sequence. This enables all built-in toolsets. A block for H5 URL handling is also provided. ```objective-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef DEBUG [[DoraemonManager shareInstance] addH5DoorBlock:^(NSString *h5Url) { //使用自己的H5容器打开这个链接 }]; [[DoraemonManager shareInstance] install]; #endif } ``` -------------------------------- ### Install DoraemonKit with Logger Support Source: https://github.com/didi/dokit/wiki/Home Use this CocoaPods subspec if your project utilizes CocoaLumberjack for logging and you want to include DoraemonKit's log display feature. ```ruby pod 'DoraemonKit/WithLogger' ``` -------------------------------- ### Install DoraemonKit Core Source: https://github.com/didi/dokit/wiki/Home This CocoaPods subspec includes the core functionalities of DoraemonKit, excluding the log display feature. It's suitable if your project does not use CocoaLumberjack for logging. ```ruby pod 'DoraemonKit/Core' ``` -------------------------------- ### Android Custom Kit Component Implementation Source: https://context7.com/didi/dokit/llms.txt Create custom tools by extending `AbstractKit` and implementing required properties and methods. This allows for custom UI elements and actions within the DoKit panel. Global API examples demonstrate common DoKit functionalities. ```kotlin // 自定义 Kit:环境切换工具 class EnvSwitchKit : AbstractKit() { // 所属分类(BIZ = 业务工具) override val category: Int get() = Category.BIZ // 显示名称(字符串资源 ID) override val name: Int get() = R.string.kit_env_switch // 图标(mipmap 资源 ID) override val icon: Int get() = R.mipmap.ic_env_switch // 点击事件:启动悬浮窗 override fun onClickWithReturn(activity: Activity): Boolean { DoKit.launchFloating(EnvSwitchDokitView::class) return true } // App 初始化回调 override fun onAppInit(context: Context?) { } } // DoKit 全局 API 使用示例 // 显示/隐藏 DoKit 主悬浮图标 DoKit.show() DoKit.hide() // 直接打开/关闭工具面板 DoKit.showToolPanel() DoKit.hideToolPanel() // 启动指定悬浮窗(单例模式) DoKit.launchFloating( targetClass = MyCustomDokitView::class, mode = DoKitViewLaunchMode.SINGLE_INSTANCE, bundle = Bundle().apply { putString("key", "value") } ) // 移除指定悬浮窗 DoKit.removeFloating(MyCustomDokitView::class) // 发送一机多控自定义事件 DoKit.sendCustomEvent( eventType = "custom_login", param = mapOf("userId" to "12345", "scene" to "test") ) ``` -------------------------------- ### Create an Independent Plugin for DoKit Source: https://github.com/didi/dokit/blob/master/Web/README.md Develop a Vue component for an independent plugin that can be used outside the DoKit main container. This example shows a draggable view. ```javascript import IndependentPlugin from "../plugin" export default new IndependentPlugin({ name: 'test-independent-plugin', component: () => import('./view.vue') }) ``` -------------------------------- ### WeChat Mini Program: Conditional Import for Frameworks Source: https://context7.com/didi/dokit/llms.txt When using third-party frameworks like Taro or uni-app, conditionally import the DoKit component based on the environment. This example shows conditional rendering in the template and potential webpack configuration for production builds. ```javascript // 使用第三方框架(如 Taro / uni-app)时按环境条件引入 // page.js const isProd = process.env.NODE_ENV === 'production'; // template 中 // isProd ? '' : // 如果框架暴露了 webpack 配置,可在生产包中排除组件 // module.exports = { // compile: { // exclude: [ // path.resolve(__dirname, '..', 'src/components/dokit-miniapp') // ] // } // }; ``` -------------------------------- ### Webpack Configuration for Third-Party Frameworks Source: https://github.com/didi/dokit/blob/master/Doc/miniapp_cn_guide.md If your framework exposes webpack configurations, you can exclude the DoKit component from the build process to optimize bundle size. This example shows how to configure 'compile.exclude'. ```javascript compile: { exclude: [ path.resolve(__dirname, '..', 'src/components/dokit-miniapp') ] } ``` -------------------------------- ### Conditional DoKit Integration in Third-Party Frameworks Source: https://github.com/didi/dokit/blob/master/Doc/miniapp_cn_guide.md For third-party frameworks, conditionally render the DoKit component based on the environment (e.g., non-production) to optimize resource usage. This example shows checking 'process.env.NODE_ENV'. ```javascript const isProd = process.env.NODE_ENV === '"production"' isProd ? '' : ``` -------------------------------- ### Webpack Configuration for Third-Party Frameworks Source: https://github.com/didi/dokit/blob/master/miniapp/README.md If your framework exposes webpack configurations, exclude the DoKit component from the build process to optimize resource packaging. This is an advanced optimization for specific framework setups. ```javascript compile: { exclude: [ path.resolve(__dirname, '..', 'src/components/dokit-miniapp') ] } ``` -------------------------------- ### Initialize DoraemonKit in Objective-C Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md Add this code to your application's launch sequence to initialize DoraemonKit. Use `installWithStartingPosition` to adjust the initial floating view position. ```objective-c #ifdef DEBUG #import #endif - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef DEBUG //默认 [[DoraemonManager shareInstance] install]; // 或者使用传入位置,解决遮挡关键区域,减少频繁移动 //[[DoraemonManager shareInstance] installWithStartingPosition:CGPointMake(66, 66)]; #endif } ``` -------------------------------- ### Flutter: Initialize DoKit with runApp Source: https://context7.com/didi/dokit/llms.txt Replace the system runApp with DoKit.runApp for automatic logging, method channel monitoring, and other non-intrusive features. Configure release mode display, zoned error handling, callbacks, and method channel blacklists. ```dart // main.dart import 'package:flutter/material.dart'; import 'package:dokit/dokit.dart'; void main() { DoKit.runApp( // 使用 DoKitApp 包裹根 Widget(必须在 main 文件内声明,不可在 package 内声明) app: DoKitApp(const MyApp()), // 是否在 Release 模式下显示 DoKit(默认 false) useInRelease: false, // 是否使用 DoKit 内部的 runZonedGuarded(false = 禁用,避免与业务冲突) useRunZoned: true, // 日志回调 logCallback: (log) => debugPrint('[DoKit Log] $log'), // 异常回调 exceptionCallback: (error, stack) => debugPrint('[DoKit Exception] $error'), // Method Channel 黑名单(过滤不需要监控的 channel) methodChannelBlackList: ['flutter/platform'], // Release 模式下执行的操作(该值为空则直接调用系统 runApp) releaseAction: () { runApp(const MyApp()); }, ); } // 异步创建根 Widget 的方式(适合需要异步初始化的场景) void mainAsync() { DoKit.runApp( appCreator: () async { // 异步初始化操作(如 Firebase、数据库等) await someAsyncInit(); return DoKitApp(const MyApp()); }, ); } ``` -------------------------------- ### Integrate DoKit For Web with CDN Source: https://github.com/didi/dokit/blob/master/Web/README.md Include Vue 3 and DoKit's CDN to use basic DoKit functionalities. Set a productId for platform-side features like data mocking. ```html ``` -------------------------------- ### Android Kotlin DoKit Initialization Source: https://context7.com/didi/dokit/llms.txt Initialize DoKit in your Application's onCreate() method using the Builder pattern. This allows for chained configuration of various parameters, including product ID, custom kits, callbacks, and port settings. ```kotlin // MyApplication.kt class MyApplication : Application() { override fun onCreate() { super.onCreate() DoKit.Builder(this) // 平台功能(数据 Mock / 健康体检等)需要在 dokit.cn 申请 productId .productId("your_product_id_from_dokit_cn") // 自定义业务工具注册(与 listKits 二选一) .customKits(linkedMapOf( "业务专区" to listOf(EnvSwitchKit(), SettingsKit()) )) // H5 任意门全局回调 .webDoorCallback(object : WebDoorManager.WebDoorCallback { override fun overrideUrlLoading(url: String) { // 使用自己的 H5 容器打开 url startH5Activity(url) } }) // 性能数据全局回调 .callBack(object : DoKitCallBack { override fun onFpsCallBack(fps: Int) { /* 帧率回调 */ } override fun onMemoryCallBack(memory: Long) { /* 内存回调 */ } }) // 禁止上传匿名统计信息(保护隐私) .disableUpload() // 加密数据库密码(key: 数据库文件名, value: 密码) .databasePass(mapOf("app.db" to "your_db_password")) // 文件管理助手 HTTP 端口(默认随机) .fileManagerHttpPort(9090) // 一机多控 WebSocket 端口 .mcWSPort(8899) .build() } } ``` -------------------------------- ### WeChat Mini Program: Page JSON Configuration Source: https://context7.com/didi/dokit/llms.txt Register the DoKit component in the page.json file of the pages where you intend to use it. Ensure the path to the component is correct. ```json // page.json:在需要使用的页面中注册组件 { "usingComponents": { "dokit": "../../components/dokit-miniapp/dist/index/index" } } ``` -------------------------------- ### Flutter: Custom Entry Points for DoKit Source: https://context7.com/didi/dokit/llms.txt Add business-specific debugging entries to Flutter's DoKit, supporting multiple custom tool partitions. Configure custom entries within the DoKitApp constructor. ```dart // 在 DoKitApp 中传入自定义入口配置 DoKitApp( const MyApp(), // 自定义入口列表(显示在 DoKit 面板"业务专区"中) customEntries: [ DoKitEntry( name: '环境切换', icon: Icons.swap_horiz, category: '业务专区', onTap: () { // 点击后的操作 Navigator.push(context, MaterialPageRoute( builder: (_) => const EnvSwitchPage(), )); }, ), DoKitEntry( name: '账号切换', icon: Icons.person_switch, category: '业务专区', onTap: () => showAccountSwitchDialog(context), ), ] ) ``` -------------------------------- ### Implement Custom Plugin Protocol Source: https://github.com/didi/dokit/wiki/Home Define a new class that conforms to the KDDoraemonPluginProtocol to create custom test modules. The pluginDidLoad method is triggered when the corresponding button in the Doraemon tool panel is tapped. ```objective-c @implementation KDDoraemonEnvPlugin - (void)pluginDidLoad{ [APP_INTERACOTR.rootNav openURL:@"KDSJ://KDDoraemonSFViewController"]; [[DoraemonManager shareInstance] hiddenHomeWindow]; } @end ``` -------------------------------- ### Implement Custom Plugin Protocol Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md Define a class that conforms to `DoraemonPluginProtocol` to create custom modules. The `pluginDidLoad` method is triggered when the plugin's button is tapped in the Doraemon panel. ```objective-c @implementation KDDoraemonEnvPlugin - (void)pluginDidLoad{ [APP_INTERACOTR.rootNav openURL:@"KDSJ://KDDoraemonSFViewController"]; [[DoraemonManager shareInstance] hiddenHomeWindow]; } @end ``` -------------------------------- ### Web: Integrate DoKit via CDN Source: https://context7.com/didi/dokit/llms.txt Include DoKit for Web directly in your HTML using a CDN for immediate access to features like logging, network inspection, and storage viewing without a build process. Ensure Vue 3 is included as a dependency. ```html My App
``` -------------------------------- ### Web: Develop Custom Plugins for DoKit Source: https://context7.com/didi/dokit/llms.txt Create custom business tools for DoKit for Web based on its core/utils/web architecture. Register plugins in `feature.js` to package them as exclusive DoKit tools. ```javascript // 1. 在 Web/packages/web/src/plugin/MyPlugin/ 下创建 Vue 组件 // MyPlugin.vue // // ``` ```javascript // 2. 将组件导出为路由插件(依托 DoKit 主容器) // MyPlugin/index.js // import MyPluginVue from './MyPlugin.vue'; // export default { // // 路由插件:在 DoKit 面板内以路由页面形式展示 // type: 'route', // name: '环境切换', // icon: 'icon-env', // component: MyPluginVue, // }; // 或导出为独立插件(脱离 DoKit 主容器,支持拖拽) // export default { // type: 'independent', // name: '页面标尺', // component: RulerPlugin, // }; ``` ```javascript // 3. 在 feature.js 中注册插件 // Web/packages/web/src/feature.js // import MyPlugin from './plugin/MyPlugin/index.js'; // import RulerPlugin from './plugin/RulerPlugin/index.js'; // export default [ // // ... 内置插件 // MyPlugin, // 路由插件 // RulerPlugin, // 独立插件 // ]; ``` -------------------------------- ### Configure DoraemonKit with Custom Plugins and H5 Door Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md A consolidated method for configuring DoraemonKit, including adding custom plugins and setting up an H5 door block for handling web URLs. Ensure this configuration is within a DEBUG preprocessor directive. ```objective-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef DEBUG [self configDoraemonKit]; #endif } //配置Doraemon工具集 - (void)configDoraemonKit{ [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"doraemon_default" desc:@"用于app内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"]; [[DoraemonManager shareInstance] addH5DoorBlock:^NSString *(NSString *h5Url) { [APP_INTERACOTR.rootNav openURL:@"KDSJ://KDWebViewController" withQuery:@{@"urlString":h5Url}]; }]; [[DoraemonManager shareInstance] install]; } ``` -------------------------------- ### Use DoKit Component in page.wxml Source: https://github.com/didi/dokit/blob/master/Doc/miniapp_cn_guide.md Include the DoKit component in your page's WXML file, providing your unique 'projectId'. ```html ``` -------------------------------- ### Import DoKit Component in page.json Source: https://github.com/didi/dokit/blob/master/Doc/miniapp_cn_guide.md Declare the DoKit component in the 'usingComponents' section of your page's JSON configuration file. Ensure the path to the component is correct. ```json { "usingComponents": { "dokit": "../../components/dokit-miniapp/dist/index/index" } } ``` -------------------------------- ### WeChat Mini Program: Page WXML Template Integration Source: https://context7.com/didi/dokit/llms.txt Include the DoKit component in your page's WXML template. Obtain your projectId from the dokit.cn platform to enable platform-specific features. ```html ``` -------------------------------- ### Configure DoraemonKit with Custom Plugins in Objective-C Source: https://github.com/didi/dokit/blob/master/iOS/README.md Configure DoraemonKit by calling a dedicated configuration method within your application's launch sequence. This method can register custom plugins and H5 door blocks. ```objective-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef DEBUG [self configDoraemonKit]; #endif } //配置Doraemon工具集 - (void)configDoraemonKit{ [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"doraemon_default" desc:@"用于app内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"]; [[DoraemonManager shareInstance] addH5DoorBlock:^(NSString *h5Url) { [APP_INTERACOTR.rootNav openURL:@"KDSJ://KDWebViewController" withQuery:@{@"urlString":h5Url}]; }]; [[DoraemonManager shareInstance] install]; } ``` -------------------------------- ### iOS Custom Plugin Integration for DoKit Source: https://context7.com/didi/dokit/llms.txt Integrate custom business-specific tools into the DoKit panel by implementing the `DoraemonPluginProtocol`. This allows for unified management of features like environment switching. You can also register H5 callbacks or use a block-based approach for simpler tools. ```objective-c // 第一步:实现插件协议 // KDDoraemonEnvPlugin.m @implementation KDDoraemonEnvPlugin - (void)pluginDidLoad { // 点击 DoKit 面板中「环境切换」按钮时触发 [APP_INTERACTOR.rootNav openURL:@"KDSJ://KDDoraemonSFViewController"]; [[DoraemonManager shareInstance] hiddenHomeWindow]; } @end // 第二步:在初始化时注册插件 - (void)configDoraemonKit { // 注册自定义插件:标题 / 图标 / 描述 / 插件类名 / 所属模块 [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"doraemon_default" desc:@"用于App内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"]; // 注册 H5 任意门回调(使用自己的 H5 容器打开链接) [[DoraemonManager shareInstance] addH5DoorBlock:^(__kindof NSString *h5Url) { [APP_INTERACTOR.rootNav openURL:@"KDSJ://KDWebViewController" withQuery:@{@"urlString": h5Url}]; }]; [[DoraemonManager shareInstance] install]; } // Block 方式(无需单独创建插件类) [[DoraemonManager shareInstance] addPluginWithTitle:@"自定义工具" icon:@"doraemon_default" desc:@"Block 方式接入示例" pluginName:nil atModule:DoraemonLocalizedString(@"业务工具") handle:^(__kindof NSDictionary *itemData) { NSLog(@"自定义工具被点击"); }]; ``` -------------------------------- ### Carthage Dependencies for DoraemonKit Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md Specify DoraemonKit dependencies using Carthage. Remember to only integrate in Debug environments to avoid polluting release code. ```bash git "https://github.com/didi/DoraemonKit.git" "c3.0.4" 或者 github "didi/DoraemonKit" ``` -------------------------------- ### Create a RouterPlugin for DoKit Source: https://github.com/didi/dokit/blob/master/Web/README.md Define a Vue component and export it as a route plugin for DoKit. This allows integrating custom views within the DoKit main container. ```javascript import RouterPlugin from "../plugin" export default new RouterPlugin({ name: 'test-router-plugin', component: () => import('./view.vue') }) ``` -------------------------------- ### Register Custom Plugins in DoKit Source: https://github.com/didi/dokit/blob/master/Web/README.md Import and declare your custom router and independent plugins in feature.js to integrate them into DoKit. This makes them available in the DoKit preview. ```javascript import { feature } from "../feature" import TestRouterPlugin from './test-router-plugin' import TestIndependentPlugin from './test-independent-plugin' feature.use(TestRouterPlugin) feature.use(TestIndependentPlugin) ``` -------------------------------- ### Conditional DoKit Integration in Third-Party Frameworks Source: https://github.com/didi/dokit/blob/master/miniapp/README.md For third-party frameworks, conditionally render the DoKit component based on the environment (e.g., non-production). This prevents the SDK from being included in production builds. ```javascript const isProd = process.env.NODE_ENV === '"production"' ``` ```html isProd ? '' : '' ``` -------------------------------- ### CocoaPods Dependencies for DoraemonKit Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md Integrate DoraemonKit core and optional subspecs using CocoaPods. Ensure these are only included in Debug configurations. ```bash pod 'DoraemonKit/Core', '~> 3.0.4', :configurations => ['Debug'] //必选 pod 'DoraemonKit/WithLogger', '~> 3.0.4', :configurations => ['Debug'] //可选 pod 'DoraemonKit/WithGPS', '~> 3.0.4', :configurations => ['Debug'] //可选 pod 'DoraemonKit/WithLoad', '~> 3.0.4', :configurations => ['Debug'] //可选 pod 'DoraemonKit/WithWeex', '~> 3.0.4', :configurations => ['Debug'] //可选 pod 'DoraemonKit/WithDatabase', '~> 3.0.4', :configurations => ['Debug'] //可选 pod 'DoraemonKit/WithMLeaksFinder', '3.0.4', :configurations => ['Debug'] //可选 ``` -------------------------------- ### Android Gradle Dependencies and AOP Plugin Configuration Source: https://context7.com/didi/dokit/llms.txt Configure your project-level and app-level Gradle files to include DoKit dependencies. The AOP plugin is optional but recommended for features like network monitoring and slow method detection. Ensure release builds use the no-op module to avoid runtime overhead. ```groovy // 项目根目录 build.gradle buildscript { repositories { mavenCentral() } dependencies { // AOP 插件(可选,用于流量监控/启动耗时/慢函数/大图检测) classpath 'io.github.didi.dokit:dokitx-plugin:3.5.0' } } // app/build.gradle apply plugin: 'com.android.application' apply plugin: 'com.didi.dokit' // 启用 AOP 插件(可选) dependencies { // 核心模块(仅 Debug) debugImplementation 'io.github.didi.dokit:dokitx:3.5.0' // 文件同步助手模块 debugImplementation 'io.github.didi.dokit:dokitx-ft:3.5.0' // 一机多控模块 debugImplementation 'io.github.didi.dokit:dokitx-mc:3.5.0' // Weex 专项模块 debugImplementation 'io.github.didi.dokit:dokitx-weex:3.5.0' // Release 空实现(保证接口不缺失) releaseImplementation 'io.github.didi.dokit:dokitx-no-op:3.5.0' } // AOP 插件配置(与 android {} 同级) dokitExt { comm { gpsSwitch true // 地图经纬度 Hook networkSwitch true // 网络抓包 bigImgSwitch true // 大图检测 webViewSwitch true // WebView JS 抓包 } slowMethod { // 调用栈模式(DOKIT_METHOD_STRATEGY=0) stackMethod { thresholdTime 10 // 函数耗时阈值(ms),低于此值不显示 enterMethods = ["com.example.app.MainActivity.onCreate"] methodBlacklist = ["com.facebook.drawee.backends.pipeline.Fresco"] } // 普通模式(DOKIT_METHOD_STRATEGY=1) normalMethod { thresholdTime 500 // 函数耗时阈值(ms) packageNames = ["com.example.app"] methodBlacklist = ["com.example.app.dokit"] } } } ``` ```properties # gradle.properties(全局开关配置) DOKIT_PLUGIN_SWITCH=true DOKIT_THIRD_LIB_SWITCH=true DOKIT_LOG_SWITCH=true DOKIT_METHOD_SWITCH=true DOKIT_METHOD_STACK_LEVEL=4 DOKIT_METHOD_STRATEGY=0 DOKIT_WEBVIEW_CLASS_NAME=com/example/app/widget/MyWebView ``` -------------------------------- ### Add Custom Plugin via Block in Objective-C Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md Register a custom plugin using a block handler for event callbacks. This provides an alternative to implementing the `DoraemonPluginProtocol` for simpler custom modules. ```objective-c [[DoraemonManager shareInstance] addPluginWithTitle:@"标题" icon:@"doraemon_default" desc:@"测试插件" pluginName:@"TestPlugin(可以为空)" atModule:DoraemonLocalizedString(@"业务工具")] handle:^(NSDictionary *itemData) { NSLog(@"handle block plugin"); }]; ``` -------------------------------- ### iOS Swift Initialization for DoKit Source: https://context7.com/didi/dokit/llms.txt Initialize DoKit in your Swift AppDelegate using conditional compilation (`#if DEBUG`) to ensure it's only enabled in Debug builds. The initialization process is similar to Objective-C. ```swift import UIKit #if DEBUG import DoraemonKit #endif @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { #if DEBUG DoraemonManager.shareInstance().install() #endif return true } } ``` -------------------------------- ### Add Custom Plugin to DoraemonManager Source: https://github.com/didi/dokit/blob/master/Doc/iOS_cn_guide.md Register your custom plugin with DoraemonKit by providing its title, icon, description, plugin name, and module. This makes it accessible within the Doraemon panel. ```objective-c [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"doraemon_default" desc:@"用于app内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"]; ``` -------------------------------- ### Add Custom Plugin to Doraemon Panel Source: https://github.com/didi/dokit/wiki/Home Register your custom plugin with DoraemonKit by calling addPluginWithTitle. This method allows you to specify the title, icon, description, plugin name, and module for your custom tool. ```objective-c [[DoraemonManager shareInstance] addPluginWithTitle:@"环境切换" icon:@"qiehuang" desc:@"用于app内部环境切换功能" pluginName:@"KDDoraemonEnvPlugin" atModule:@"业务专区"]; ``` -------------------------------- ### iOS CocoaPods Integration for DoKit Source: https://context7.com/didi/dokit/llms.txt Integrate DoraemonKit into your iOS project using CocoaPods. The 'Core' module is required, while others are optional extensions for specific functionalities like logging, GPS simulation, or database debugging. Ensure these are only included in 'Debug' configurations. ```ruby target 'YourApp' do # 核心模块(必选) pod 'DoraemonKit/Core', '~> 3.0.4', :configurations => ['Debug'] # 可选:基于 CocoaLumberjack 的日志显示 pod 'DoraemonKit/WithLogger', '~> 3.0.4', :configurations => ['Debug'] # 可选:GPS 模拟定位 pod 'DoraemonKit/WithGPS', '~> 3.0.4', :configurations => ['Debug'] # 可选:Load 方法耗时检测 pod 'DoraemonKit/WithLoad', '~> 3.0.4', :configurations => ['Debug'] # 可选:Weex 专项工具 pod 'DoraemonKit/WithWeex', '~> 3.0.4', :configurations => ['Debug'] # 可选:基于 YYDebugDatabase 的数据库调试 pod 'DoraemonKit/WithDatabase', '~> 3.0.4', :configurations => ['Debug'] # 可选:基于 MLeaksFinder 的内存泄漏检测 pod 'DoraemonKit/WithMLeaksFinder','3.0.4', :configurations => ['Debug'] end ```