capacitor-app-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCapacitor App Development
Capacitor 应用开发
General guidance for developing cross-platform apps with Capacitor, covering core concepts, CLI usage, app configuration, platform management, and troubleshooting.
本内容为使用Capacitor开发跨平台应用提供通用指导,涵盖核心概念、CLI使用、应用配置、平台管理及故障排查。
Prerequisites
前提条件
- Capacitor 6, 7, or 8 app already created and initialized.
- Node.js and npm installed (Node 18+ for Cap 6, Node 20+ for Cap 7, Node 22+ for Cap 8).
- For Android: Android Studio installed.
- For iOS: Xcode installed on macOS.
- 已创建并初始化Capacitor 6、7或8版本的应用。
- 已安装Node.js和npm(Cap 6需Node 18+,Cap 7需Node 20+,Cap 8需Node 22+)。
- 针对Android:已安装Android Studio。
- 针对iOS:已在macOS上安装Xcode。
Agent Behavior
Agent行为规范
- Auto-detect before asking. Inspect the project for platforms (,
android/), framework (ios/,vite.config.ts,angular.json,webpack.config.js), Capacitor version (next.config.jsin@capacitor/core), and iOS dependency manager (package.jsonfor CocoaPods vs. SPM).ios/App/Podfile - Route to the right reference file. Use the topic index below to identify the correct reference file and read it before providing guidance.
- One topic at a time. Address the user's specific question. Do not provide a general overview unless explicitly requested.
- Prefer actionable instructions. Provide exact file paths, commands, and diff blocks rather than conceptual explanations.
- 先自动检测再询问:检查项目的平台目录(、
android/)、框架配置文件(ios/、vite.config.ts、angular.json、webpack.config.js)、Capacitor版本(next.config.js中的package.json)以及iOS依赖管理器(通过@capacitor/core判断是CocoaPods还是SPM)。ios/App/Podfile - 关联正确的参考文件:使用下方的主题索引确定对应的参考文件,查阅后再提供指导。
- 一次处理一个主题:针对用户的具体问题进行解答,除非明确要求,否则不要提供通用概述。
- 优先提供可操作的指令:提供精确的文件路径、命令和代码差异块,而非仅概念性解释。
Procedures
操作流程
Step 1: Identify the Topic
步骤1:确定主题
Match the user's request to a topic from the index below. If the request spans multiple topics, address them sequentially.
If the request matches a topic covered by a different skill, redirect the user to that skill (see Related Skills at the bottom).
将用户的请求与下方索引中的主题匹配。如果请求涉及多个主题,按顺序逐一处理。
如果请求属于其他技能覆盖的主题,引导用户使用对应技能(见底部的相关技能)。
Step 2: Analyze the Project
步骤2:分析项目
Auto-detect the following by reading project files:
- Capacitor version: Read version from
@capacitor/core.package.json - Platforms: Check which directories exist (,
android/).ios/ - Framework: Check for build tool config files.
- Capacitor config format: Check for or
capacitor.config.ts.capacitor.config.json - iOS dependency manager: Check for (CocoaPods) or SPM usage.
ios/App/Podfile
通过读取项目文件自动检测以下内容:
- Capacitor版本:从中读取
package.json的版本。@capacitor/core - 平台:检查是否存在对应目录(、
android/)。ios/ - 框架:检查构建工具配置文件。
- Capacitor配置格式:检查是否存在或
capacitor.config.ts。capacitor.config.json - iOS依赖管理器:检查是否使用(CocoaPods)或SPM。
ios/App/Podfile
Step 3: Read the Reference File and Apply Guidance
步骤3:查阅参考文件并应用指导
Read the reference file for the matched topic and apply the instructions to the user's project.
查阅匹配主题对应的参考文件,并将指导内容应用到用户的项目中。
Topic Index
主题索引
| Topic | Reference |
|---|---|
| Core concepts (native bridge, how Capacitor works) | |
| Capacitor platforms (Android, iOS, Electron, PWA) | |
| Capacitor CLI commands | |
App configuration ( | |
| Splash screens and app icons | |
| Deep links and universal links | |
| Android edge-to-edge support | |
| Android safe area handling | |
| Live reload setup | |
| Storage solutions | |
| File handling best practices | |
| Security best practices | |
| iOS package managers (SPM, CocoaPods) | |
| CI/CD for Capacitor apps | |
| Testing (unit and E2E) | |
| Cross-platform best practices | |
| Android troubleshooting | |
| iOS troubleshooting | |
| 主题 | 参考文件 |
|---|---|
| 核心概念(原生桥接、Capacitor工作原理) | |
| Capacitor平台(Android、iOS、Electron、PWA) | |
| Capacitor CLI命令 | |
应用配置( | |
| 启动屏与应用图标 | |
| 深度链接与通用链接 | |
| Android全屏适配支持 | |
| Android安全区域处理 | |
| 热重载设置 | |
| 存储方案 | |
| 文件处理最佳实践 | |
| 安全最佳实践 | |
| iOS包管理器(SPM、CocoaPods) | |
| Capacitor应用CI/CD | |
| 测试(单元测试与E2E测试) | |
| 跨平台最佳实践 | |
| Android故障排查 | |
| iOS故障排查 | |
Error Handling
故障处理
- fails: Verify
npx cap syncand@capacitor/coreversions match. On iOS with CocoaPods, run@capacitor/cli. On Android, sync Gradle files in Android Studio.cd ios/App && pod install - Android build fails after configuration changes: Clean the build with , then rebuild.
cd android && ./gradlew clean - iOS build fails after configuration changes: Clean the build folder in Xcode (Product > Clean Build Folder) or delete and run
ios/App/Pods.cd ios/App && pod install - Plugin not found at runtime: Run after any plugin installation. Verify the plugin appears in
npx cap syncor the native project.capacitor.config - Live reload not connecting: Verify the device and development machine are on the same network. Check that the server URL in uses the correct LAN IP address.
capacitor.config - Deep links not working: Verify the site association file is accessible at (iOS) or
https://<domain>/.well-known/apple-app-site-association(Android). Verify the app is signed with the correct certificate.https://<domain>/.well-known/assetlinks.json
- 执行失败:验证
npx cap sync和@capacitor/core的版本是否一致。在使用CocoaPods的iOS项目中,执行@capacitor/cli。在Android项目中,在Android Studio中同步Gradle文件。cd ios/App && pod install - 配置变更后Android构建失败:执行清理构建文件,然后重新构建。
cd android && ./gradlew clean - 配置变更后iOS构建失败:在Xcode中清理构建文件夹(Product > Clean Build Folder),或删除并执行
ios/App/Pods。cd ios/App && pod install - 运行时找不到插件:安装任何插件后执行。验证插件是否已添加到
npx cap sync或原生项目中。capacitor.config - 热重载无法连接:验证设备与开发机器处于同一网络。检查中的服务器URL是否使用了正确的局域网IP地址。
capacitor.config - 深度链接无法工作:验证站点关联文件是否可通过(iOS)或
https://<domain>/.well-known/apple-app-site-association(Android)访问。验证应用是否使用正确的证书签名。https://<domain>/.well-known/assetlinks.json
Related Skills
相关技能
- — Create a new Capacitor app.
capacitor-app-creation - — Angular-specific Capacitor development.
capacitor-angular - — React-specific Capacitor development.
capacitor-react - — Vue-specific Capacitor development.
capacitor-vue - — Install and configure Capacitor plugins.
capacitor-plugins - — Create custom Capacitor plugins.
capacitor-plugin-development - — Upgrade Capacitor to a newer major version.
capacitor-app-upgrades - — Set up in-app purchases.
capacitor-in-app-purchases - — Cloud builds, live updates, and app store publishing.
capawesome-cloud
- — 创建新的Capacitor应用。
capacitor-app-creation - — Angular专属Capacitor开发。
capacitor-angular - — React专属Capacitor开发。
capacitor-react - — Vue专属Capacitor开发。
capacitor-vue - — 安装与配置Capacitor插件。
capacitor-plugins - — 开发自定义Capacitor插件。
capacitor-plugin-development - — 将Capacitor升级到更高的主版本。
capacitor-app-upgrades - — 配置内购功能。
capacitor-in-app-purchases - — 云构建、热更新与应用商店发布。
capawesome-cloud