Setup
On first use, read setup.md for integration guidelines.
When to Use
User works with Android Studio IDE. Agent helps with debugging tools, profiler, layout inspector, code navigation, refactoring, and keyboard shortcuts.
Architecture
Memory at ~/android-studio/. See memory-template.md for structure.
CODEBLOCK0
Quick Reference
| Topic | File |
|---|
| Setup process | INLINECODE3 |
| Memory template |
memory-template.md |
| Shortcuts |
shortcuts.md |
| Debugging |
debugging.md |
Core Rules
1. Check IDE Version First
Before suggesting features, confirm Android Studio version. Features vary significantly between Arctic Fox, Bumblebee, Flamingo, Hedgehog, and newer versions.
2. Platform-Aware Shortcuts
| Action | macOS | Windows/Linux |
|---|
| Search Everywhere | Double Shift | Double Shift |
| Find Action |
Cmd+Shift+A | Ctrl+Shift+A |
| Recent Files | Cmd+E | Ctrl+E |
| Navigate to Class | Cmd+O | Ctrl+N |
| Navigate to File | Cmd+Shift+O | Ctrl+Shift+N |
| Refactor This | Ctrl+T | Ctrl+Alt+Shift+T |
| Run | Ctrl+R | Shift+F10 |
| Debug | Ctrl+D | Shift+F9 |
3. Use IDE Tools Over Manual Inspection
- - Layout Inspector over print debugging for UI issues
- Profiler over manual timing for performance
- Database Inspector over manual queries
- Network Inspector over logging requests
4. Leverage Code Generation
- - Live Templates for boilerplate (type abbreviation + Tab)
- File Templates for new components
- Generate menu (Cmd/Alt+N) for constructors, getters, overrides
5. Debugging Strategy
- 1. Breakpoints with conditions for targeted debugging
- Evaluate Expression (Alt+F8) for runtime inspection
- Watches for tracking variables across frames
- Frame inspection to navigate call stack
Debugging Traps
- - Setting breakpoints in hot loops → freezes IDE. Use conditional breakpoints.
- Debugging release builds → missing symbols. Debug with debug variant.
- Ignoring Logcat filters → drowning in logs. Filter by app package or tag.
- Not using "Attach Debugger" → missing app startup. Attach to running process.
Profiling Traps
- - Profiling debug builds → misleading performance. Profile release builds.
- CPU Profiler without filtering → overwhelming data. Focus on specific methods.
- Memory Profiler heap dumps during GC → skewed results. Trigger GC first.
- Ignoring Network Profiler → missing slow API calls. Always check network timing.
Essential IDE Features
Layout Inspector
- - Inspect live view hierarchy in running app
- 3D mode for seeing layer depth
- Attribute inspection for debugging constraints
- Works with Compose and View system
Database Inspector
- - Query Room databases in real-time
- Edit values directly for testing
- Export data for analysis
- Requires API 26+ on device
Network Inspector
- - Inspect OkHttp/Retrofit requests without code changes
- View request/response bodies
- Timeline for identifying slow calls
- Requires enabling in manifest for release
App Inspection
- - Combined view of Database, Network, Background Tasks
- WorkManager task monitoring
- Background task scheduling inspection
Profiler Tools
| Tool | Use Case |
|---|
| CPU Profiler | Method timing, thread analysis |
| Memory Profiler |
Leaks, allocation tracking |
| Energy Profiler | Battery usage patterns |
| Network Profiler | Request timing, payload size |
Refactoring Shortcuts
| Refactoring | macOS | Windows/Linux |
|---|
| Rename | Shift+F6 | Shift+F6 |
| Extract Method |
Cmd+Alt+M | Ctrl+Alt+M |
| Extract Variable | Cmd+Alt+V | Ctrl+Alt+V |
| Extract Constant | Cmd+Alt+C | Ctrl+Alt+C |
| Inline | Cmd+Alt+N | Ctrl+Alt+N |
| Move | F6 | F6 |
| Change Signature | Cmd+F6 | Ctrl+F6 |
Build Configuration
Gradle Sync Issues
- - File → Invalidate Caches / Restart for persistent issues
- Delete
.gradle and .idea folders as last resort - Check Gradle JDK in Preferences → Build → Gradle
Build Variants
- - Select variant in Build Variants panel
- Debug vs Release affects debugging capabilities
- Product flavors for different app configurations
SDK Manager
- - Tools → SDK Manager for Android SDK updates
- Install platform tools matching target devices
- Keep build tools updated for latest features
Emulator Tips
- - Cold Boot vs Quick Boot: use Quick Boot for speed
- Extended Controls (three dots) for sensors, location, battery
- Snapshots for saving specific device states
- Device mirroring for physical device control
Plugin Recommendations
| Plugin | Purpose |
|---|
| Key Promoter X | Learn shortcuts |
| Rainbow Brackets |
Bracket matching |
| ADB Idea | Quick ADB commands |
| JSON To Kotlin Class | Data class generation |
| Compose Color Preview | Color visualization |
Related Skills
Install with
clawhub install <slug> if user confirms:
- -
android — Android development patterns - INLINECODE11 — Kotlin language features
- INLINECODE12 — Java language patterns
Feedback
- - If useful: INLINECODE13
- Stay updated: INLINECODE14
设置
首次使用时,请阅读 setup.md 了解集成指南。
使用时机
用户使用 Android Studio IDE 时。助手协助使用调试工具、性能分析器、布局检查器、代码导航、重构和键盘快捷键。
架构
记忆存储在 ~/android-studio/ 目录下。结构参见 memory-template.md。
~/android-studio/
├── memory.md # 偏好设置和项目上下文
└── shortcuts.md # 已学习的自定义快捷键
快速参考
memory-template.md |
| 快捷键 | shortcuts.md |
| 调试 | debugging.md |
核心规则
1. 首先检查 IDE 版本
在建议功能前,先确认 Android Studio 版本。Arctic Fox、Bumblebee、Flamingo、Hedgehog 及更新版本之间的功能差异很大。
2. 平台感知快捷键
| 操作 | macOS | Windows/Linux |
|---|
| 全局搜索 | 双击 Shift | 双击 Shift |
| 查找操作 |
Cmd+Shift+A | Ctrl+Shift+A |
| 最近文件 | Cmd+E | Ctrl+E |
| 导航到类 | Cmd+O | Ctrl+N |
| 导航到文件 | Cmd+Shift+O | Ctrl+Shift+N |
| 重构此 | Ctrl+T | Ctrl+Alt+Shift+T |
| 运行 | Ctrl+R | Shift+F10 |
| 调试 | Ctrl+D | Shift+F9 |
3. 使用 IDE 工具而非手动检查
- - 使用布局检查器而非打印调试处理 UI 问题
- 使用性能分析器而非手动计时处理性能问题
- 使用数据库检查器而非手动查询
- 使用网络检查器而非记录请求
4. 利用代码生成
- - 实时模板用于样板代码(输入缩写 + Tab)
- 文件模板用于新组件
- 生成菜单(Cmd/Alt+N)用于构造函数、getter、重写方法
5. 调试策略
- 1. 带条件的断点用于针对性调试
- 计算表达式(Alt+F8)用于运行时检查
- 监视变量以跨帧跟踪
- 帧检查以导航调用栈
调试陷阱
- - 在热循环中设置断点 → 导致 IDE 冻结。应使用条件断点。
- 调试发布版本 → 缺少符号。应使用调试变体进行调试。
- 忽略 Logcat 过滤器 → 日志信息过多。按应用包名或标签过滤。
- 不使用附加调试器 → 错过应用启动。应附加到正在运行的进程。
性能分析陷阱
- - 分析调试版本 → 性能数据误导。应分析发布版本。
- 未过滤的 CPU 分析器 → 数据过多。应聚焦特定方法。
- 在垃圾回收期间进行内存分析器堆转储 → 结果偏差。应先触发垃圾回收。
- 忽略网络分析器 → 遗漏慢速 API 调用。始终检查网络时序。
必备 IDE 功能
布局检查器
- - 检查运行中应用的实时视图层级
- 3D 模式查看图层深度
- 属性检查用于调试约束
- 支持 Compose 和 View 系统
数据库检查器
- - 实时查询 Room 数据库
- 直接编辑值进行测试
- 导出数据用于分析
- 设备需 API 26+
网络检查器
- - 无需修改代码即可检查 OkHttp/Retrofit 请求
- 查看请求/响应体
- 时间线用于识别慢速调用
- 发布版本需在清单中启用
应用检查
- - 数据库、网络、后台任务的综合视图
- WorkManager 任务监控
- 后台任务调度检查
性能分析工具
| 工具 | 使用场景 |
|---|
| CPU 分析器 | 方法计时、线程分析 |
| 内存分析器 |
泄漏、分配跟踪 |
| 能耗分析器 | 电池使用模式 |
| 网络分析器 | 请求计时、负载大小 |
重构快捷键
| 重构操作 | macOS | Windows/Linux |
|---|
| 重命名 | Shift+F6 | Shift+F6 |
| 提取方法 |
Cmd+Alt+M | Ctrl+Alt+M |
| 提取变量 | Cmd+Alt+V | Ctrl+Alt+V |
| 提取常量 | Cmd+Alt+C | Ctrl+Alt+C |
| 内联 | Cmd+Alt+N | Ctrl+Alt+N |
| 移动 | F6 | F6 |
| 更改签名 | Cmd+F6 | Ctrl+F6 |
构建配置
Gradle 同步问题
- - 文件 → 清除缓存/重启 用于持久性问题
- 最后手段:删除 .gradle 和 .idea 文件夹
- 在偏好设置 → 构建 → Gradle 中检查 Gradle JDK
构建变体
- - 在构建变体面板中选择变体
- 调试与发布版本影响调试能力
- 产品风味用于不同应用配置
SDK 管理器
- - 工具 → SDK 管理器用于 Android SDK 更新
- 安装与目标设备匹配的平台工具
- 保持构建工具更新以获取最新功能
模拟器技巧
- - 冷启动 vs 快速启动:使用快速启动提高速度
- 扩展控件(三点图标)用于传感器、位置、电池
- 快照用于保存特定设备状态
- 设备镜像用于物理设备控制
插件推荐
| 插件 | 用途 |
|---|
| Key Promoter X | 学习快捷键 |
| Rainbow Brackets |
括号匹配 |
| ADB Idea | 快速 ADB 命令 |
| JSON To Kotlin Class | 数据类生成 |
| Compose Color Preview | 颜色可视化 |
相关技能
如果用户确认,使用 clawhub install 安装:
- - android — Android 开发模式
- kotlin — Kotlin 语言特性
- java — Java 语言模式
反馈
- - 如果有用:clawhub star android-studio
- 保持更新:clawhub sync