重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
cordova-to-capacitor by cap-go/capgo-skills
npx skills add https://github.com/cap-go/capgo-skills --skill cordova-to-capacitor包含 Shell 命令
此技能包含可能执行系统命令的 shell 命令指令(!command``)。在安装前请仔细审查。
从 Apache Cordova/PhoneGap 迁移到 Capacitor 的逐步指南。
当前与迁移相关的包:!node -e "const fs=require('fs');if(!fs.existsSync('package.json'))process.exit(0);const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const out=[];for(const section of ['dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(name.includes('cordova')||name.startsWith('@capacitor/')||name.startsWith('@ionic-enterprise/'))out.push(section+'.'+name+'='+version)}}console.log(out.sort().join('\n'))"
相关的配置和平台路径:!find . -maxdepth 3 \( -name 'config.xml' -o -name 'capacitor.config.json' -o -name 'capacitor.config.ts' -o -name 'capacitor.config.js' -o -path './ios' -o -path './android' \)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 方面 | Cordova | Capacitor |
|---|---|---|
| 原生 IDE | 通过 CLI 构建 | 一流的 Xcode/Android Studio 支持 |
| 插件管理 | 独立的生态系统 | npm 包 |
| 更新 | 需要完整的应用商店审核 | 通过 Capgo 实现实时更新 |
| Web 应用平台 | 任意 | 任意(React, Vue, Angular 等) |
| 维护 | 放缓 | 积极开发 |
| TypeScript | 有限支持 | 完全支持 |
| 现代 API | 较旧的模式 | 基于 Promise 的现代 API |
从上面注入的快照开始,然后再进行手动检查。
检查 Cordova 版本:
cordova --version
cordova platform version
列出已安装的插件:
cordova plugin list
审查 config.xml:
cat config.xml
在您现有的 Cordova 项目中:
# 安装 Capacitor
npm install @capacitor/core @capacitor/cli
# 初始化 Capacitor
npx cap init
当提示时:
com.company.app)wwwCapacitor 不修改 Web 资源。单独添加平台:
# 添加 iOS 平台
npm install @capacitor/ios
npx cap add ios
# 添加 Android 平台
npm install @capacitor/android
npx cap add android
这将创建:
ios/ 目录android/ 目录关键:首先检查插件兼容性。
| Cordova 插件 | Capacitor 等效插件 | 安装命令 |
|---|---|---|
| cordova-plugin-camera | @capacitor/camera | npm install @capacitor/camera |
| cordova-plugin-geolocation | @capacitor/geolocation | npm install @capacitor/geolocation |
| cordova-plugin-device | @capacitor/device | npm install @capacitor/device |
| cordova-plugin-network-information | @capacitor/network | npm install @capacitor/network |
| cordova-plugin-statusbar | @capacitor/status-bar | npm install @capacitor/status-bar |
| cordova-plugin-splashscreen | @capacitor/splash-screen | npm install @capacitor/splash-screen |
| cordova-plugin-keyboard | @capacitor/keyboard | npm install @capacitor/keyboard |
| cordova-plugin-dialogs | @capacitor/dialog | npm install @capacitor/dialog |
| cordova-plugin-file | @capacitor/filesystem | npm install @capacitor/filesystem |
| cordova-plugin-inappbrowser | @capacitor/browser | npm install @capacitor/browser |
| cordova-plugin-media | @capacitor/media | 自定义或使用 @capgo 插件 |
| cordova-plugin-vibration | @capacitor/haptics | npm install @capacitor/haptics |
| cordova-plugin-local-notifications | @capacitor/local-notifications | npm install @capacitor/local-notifications |
| cordova-plugin-push | @capacitor/push-notifications | npm install @capacitor/push-notifications |
用于生物识别:
# Cordova
cordova plugin add cordova-plugin-fingerprint-aio
# Capacitor
npm install @capgo/capacitor-native-biometric
用于支付:
# Cordova
cordova plugin add cordova-plugin-purchase
# Capacitor
npm install @capgo/capacitor-purchases
用于社交登录:
# Facebook
npm install @capgo/capacitor-social-login
# Google
npm install @codetrix-studio/capacitor-google-auth
查看完整的插件目录: https://github.com/Cap-go/awesome-capacitor
Cordova(旧):
document.addEventListener('deviceready', () => {
navigator.camera.getPicture(success, error, options);
});
Capacitor(新):
import { Camera } from '@capacitor/camera';
// 无需 deviceready 事件
const image = await Camera.getPhoto({
quality: 90,
allowEditing: true,
resultType: CameraResultType.Uri
});
设备信息:
// Cordova
const uuid = device.uuid;
const platform = device.platform;
// Capacitor
import { Device } from '@capacitor/device';
const info = await Device.getId();
const platform = await Device.getInfo();
网络状态:
// Cordova
const networkState = navigator.connection.type;
// Capacitor
import { Network } from '@capacitor/network';
const status = await Network.getStatus();
console.log('已连接:', status.connected);
地理位置:
// Cordova
navigator.geolocation.getCurrentPosition(success, error);
// Capacitor
import { Geolocation } from '@capacitor/geolocation';
const position = await Geolocation.getCurrentPosition();
Capacitor 不需要 deviceready。 插件立即工作。
// Cordova(移除这个)
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
// 您的代码
}
// Capacitor(直接使用即可)
import { Camera } from '@capacitor/camera';
async function takePicture() {
const photo = await Camera.getPhoto();
}
Cordova 使用 config.xml。Capacitor 使用 capacitor.config.ts
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.company.app', // 来自 config.xml 的 widget id
appName: 'My App', // 来自 config.xml 的 name
webDir: 'www', // 来自 Cordova 构建输出
server: {
androidScheme: 'https'
},
plugins: {
SplashScreen: {
launchShowDuration: 3000,
backgroundColor: '#ffffff',
androidScaleType: 'CENTER_CROP',
showSpinner: false
}
}
};
export default config;
首选项:
<!-- Cordova config.xml -->
<preference name="Orientation" value="portrait" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
Capacitor 等效方案:
@capacitor/status-bar 插件平台特定配置:
<!-- Cordova config.xml -->
<platform name="ios">
<allow-intent href="itms:*" />
</platform>
Capacitor 等效方案:
// capacitor.config.ts
const config: CapacitorConfig = {
ios: {
contentInset: 'always',
},
android: {
allowMixedContent: true,
}
};
Capacitor 需要显式的权限配置。
添加到 ios/App/App/Info.plist:
<key>NSCameraUsageDescription</key>
<string>我们需要相机访问权限来拍摄照片</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>我们需要照片库访问权限来选择图片</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>我们需要位置信息来显示附近地点</string>
<key>NSMicrophoneUsageDescription</key>
<string>我们需要麦克风访问权限来进行音频录制</string>
添加到 android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
将 Web 代码与原生项目同步:
npx cap sync
这会复制:
www/ 到原生项目为 iOS 构建:
npx cap open ios
# 然后在 Xcode 中构建 (Cmd+R)
为 Android 构建:
npx cap open android
# 然后在 Android Studio 中构建 (Run)
测试所有插件功能:
检查:
迁移完成并测试后:
# 移除 Cordova 平台
cordova platform remove ios
cordova platform remove android
# 移除 Cordova
npm uninstall cordova
npm uninstall cordova-ios
npm uninstall cordova-android
# 移除 Cordova 插件
cordova plugin list | xargs -I {} cordova plugin remove {}
# 移除 config.xml(备份后)
mv config.xml config.xml.backup
问题:
Error: Plugin not found
解决方案:
npm listnpx cap sync问题: Cordova 的 deviceready 事件在 Capacitor 中不存在。
解决方案: 移除所有 deviceready 事件监听器。Capacitor 插件立即工作。
// 移除这个
document.addEventListener('deviceready', onDeviceReady);
// 使用这个
import { App } from '@capacitor/app';
App.addListener('appStateChange', (state) => {
console.log('应用状态已更改:', state.isActive);
});
问题: 应用显示白屏或崩溃。
解决方案:
webDir 是否指向正确的构建输出目录npm run buildnpx cap sync问题: 相机/位置等静默失败。
解决方案:
import { Camera } from '@capacitor/camera';
// Capacitor 会自动处理权限提示
const photo = await Camera.getPhoto();
问题: 一些第三方 Cordova 插件仍然引用 Cordova 全局对象。
解决方案: 使用 Capacitor Cordova 兼容层:
npm install cordova-plugin-example
npx cap sync
Capacitor 包含 Cordova 兼容性,但是:
您可以在迁移期间同时运行 Cordova 和 Capacitor。
准备就绪后,完全移除 Cordova。
cordova plugin listnpm install @capacitor/plugin-namedeviceready 事件监听器npx cap syncCapacitor 支持无需应用商店审核的即时更新。
迁移后,添加 Capgo 以实现 OTA 更新:
# 安装 Capgo 插件
npm install @capgo/capacitor-updater
# 在 capgo.app 创建账户
npm install -g @capgo/cli
capgo login
# 初始化和部署
capgo init
npm run build
capgo upload
用户会立即获得更新。详情请参阅 capgo-live-updates 技能。
| 应用大小 | 预计时间 |
|---|---|
| 小型(1-3 个插件) | 2-4 小时 |
| 中型(4-8 个插件) | 1-2 天 |
| 大型(9+ 个插件) | 3-5 天 |
| 企业级(自定义插件) | 1-2 周 |
从 Cordova 迁移到 Capacitor 后:
✅ 更快的开发 - 直接访问 Xcode/Android Studio ✅ 实时更新 - 无需应用商店审核即可部署更新(使用 Capgo) ✅ 更好的 TypeScript - 完整的类型安全 ✅ 现代 API - 基于 Promise,async/await ✅ 积极维护 - 定期更新和改进 ✅ 更好的调试 - 原生 IDE 调试工具 ✅ 改进的性能 - 优化的原生桥接
capacitor-ci-cd 技能)capgo-live-updates 技能)capacitor-app-store 技能)每周安装量
51
仓库
GitHub Stars
20
首次出现
2026年2月13日
安全审计
安装于
gemini-cli50
codex49
opencode49
github-copilot48
amp47
kimi-cli47
Contains Shell Commands
This skill contains shell command directives (!command``) that may execute system commands. Review carefully before installing.
Step-by-step guide for migrating from Apache Cordova/PhoneGap to Capacitor.
Current migration-related packages: !node -e "const fs=require('fs');if(!fs.existsSync('package.json'))process.exit(0);const pkg=JSON.parse(fs.readFileSync('package.json','utf8'));const out=[];for(const section of ['dependencies','devDependencies']){for(const [name,version] of Object.entries(pkg[section]||{})){if(name.includes('cordova')||name.startsWith('@capacitor/')||name.startsWith('@ionic-enterprise/'))out.push(section+'.'+name+'='+version)}}console.log(out.sort().join('\n'))"
Relevant config and platform paths: !find . -maxdepth 3 \( -name 'config.xml' -o -name 'capacitor.config.json' -o -name 'capacitor.config.ts' -o -name 'capacitor.config.js' -o -path './ios' -o -path './android' \)
| Aspect | Cordova | Capacitor |
|---|---|---|
| Native IDE | Builds via CLI | First-class Xcode/Android Studio |
| Plugin Management | Separate ecosystem | npm packages |
| Updates | Full app store review | Live updates with Capgo |
| Web App Platform | Any | Any (React, Vue, Angular, etc.) |
| Maintenance | Slowing down | Active development |
| TypeScript | Limited | Full support |
| Modern APIs | Older patterns | Modern Promise-based APIs |
Start from the injected snapshot above before falling back to manual inspection.
Check Cordova version:
cordova --version
cordova platform version
List installed plugins:
cordova plugin list
Review config.xml:
cat config.xml
In your existing Cordova project:
# Install Capacitor
npm install @capacitor/core @capacitor/cli
# Initialize Capacitor
npx cap init
When prompted:
com.company.app)www for Cordova projectsCapacitor doesn't modify web assets. Add platforms separately:
# Add iOS platform
npm install @capacitor/ios
npx cap add ios
# Add Android platform
npm install @capacitor/android
npx cap add android
This creates:
ios/ directory with Xcode projectandroid/ directory with Android Studio projectCRITICAL: Check plugin compatibility first.
| Cordova Plugin | Capacitor Equivalent | Install Command |
|---|---|---|
| cordova-plugin-camera | @capacitor/camera | npm install @capacitor/camera |
| cordova-plugin-geolocation | @capacitor/geolocation | npm install @capacitor/geolocation |
| cordova-plugin-device | @capacitor/device | npm install @capacitor/device |
| cordova-plugin-network-information | @capacitor/network | npm install @capacitor/network |
| cordova-plugin-statusbar | @capacitor/status-bar |
For biometrics:
# Cordova
cordova plugin add cordova-plugin-fingerprint-aio
# Capacitor
npm install @capgo/capacitor-native-biometric
For payments:
# Cordova
cordova plugin add cordova-plugin-purchase
# Capacitor
npm install @capgo/capacitor-purchases
For social login:
# Facebook
npm install @capgo/capacitor-social-login
# Google
npm install @codetrix-studio/capacitor-google-auth
Check the full plugin catalog: https://github.com/Cap-go/awesome-capacitor
Cordova (old):
document.addEventListener('deviceready', () => {
navigator.camera.getPicture(success, error, options);
});
Capacitor (new):
import { Camera } from '@capacitor/camera';
// No deviceready event needed
const image = await Camera.getPhoto({
quality: 90,
allowEditing: true,
resultType: CameraResultType.Uri
});
Device Information:
// Cordova
const uuid = device.uuid;
const platform = device.platform;
// Capacitor
import { Device } from '@capacitor/device';
const info = await Device.getId();
const platform = await Device.getInfo();
Network Status:
// Cordova
const networkState = navigator.connection.type;
// Capacitor
import { Network } from '@capacitor/network';
const status = await Network.getStatus();
console.log('Connected:', status.connected);
Geolocation:
// Cordova
navigator.geolocation.getCurrentPosition(success, error);
// Capacitor
import { Geolocation } from '@capacitor/geolocation';
const position = await Geolocation.getCurrentPosition();
Capacitor doesn't need deviceready. Plugins work immediately.
// Cordova (remove this)
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
// Your code
}
// Capacitor (just use directly)
import { Camera } from '@capacitor/camera';
async function takePicture() {
const photo = await Camera.getPhoto();
}
Cordova uses config.xml. Capacitor uses capacitor.config.ts
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.company.app', // From config.xml widget id
appName: 'My App', // From config.xml name
webDir: 'www', // From Cordova build output
server: {
androidScheme: 'https'
},
plugins: {
SplashScreen: {
launchShowDuration: 3000,
backgroundColor: '#ffffff',
androidScaleType: 'CENTER_CROP',
showSpinner: false
}
}
};
export default config;
Preferences:
<!-- Cordova config.xml -->
<preference name="Orientation" value="portrait" />
<preference name="StatusBarOverlaysWebView" value="false" />
<preference name="StatusBarBackgroundColor" value="#000000" />
Capacitor equivalent:
@capacitor/status-bar pluginPlatform-specific config:
<!-- Cordova config.xml -->
<platform name="ios">
<allow-intent href="itms:*" />
</platform>
Capacitor equivalent:
// capacitor.config.ts
const config: CapacitorConfig = {
ios: {
contentInset: 'always',
},
android: {
allowMixedContent: true,
}
};
Capacitor requires explicit permission configuration.
Add to ios/App/App/Info.plist:
<key>NSCameraUsageDescription</key>
<string>We need camera access to take photos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need photo library access to select images</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need location to show nearby places</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need microphone access for audio recording</string>
Add to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Sync web code with native projects:
npx cap sync
This copies:
www/ to native projectsBuild for iOS:
npx cap open ios
# Then build in Xcode (Cmd+R)
Build for Android:
npx cap open android
# Then build in Android Studio (Run)
Test all plugin functionality:
Check for:
Once migration is complete and tested:
# Remove Cordova platforms
cordova platform remove ios
cordova platform remove android
# Remove Cordova
npm uninstall cordova
npm uninstall cordova-ios
npm uninstall cordova-android
# Remove Cordova plugins
cordova plugin list | xargs -I {} cordova plugin remove {}
# Remove config.xml (after backing up)
mv config.xml config.xml.backup
Problem:
Error: Plugin not found
Solution:
npm listnpx cap syncProblem: Cordova's deviceready event doesn't exist in Capacitor.
Solution: Remove all deviceready event listeners. Capacitor plugins work immediately.
// Remove this
document.addEventListener('deviceready', onDeviceReady);
// Use this
import { App } from '@capacitor/app';
App.addListener('appStateChange', (state) => {
console.log('App state changed:', state.isActive);
});
Problem: App shows white screen or crashes.
Solution:
webDir in capacitor.config.ts points to correct build outputnpm run buildnpx cap syncProblem: Camera/location/etc. fail silently.
Solution:
import { Camera } from '@capacitor/camera';
// Capacitor handles permission prompts automatically
const photo = await Camera.getPhoto();
Problem: Some third-party Cordova plugins still reference Cordova global.
Solution: Use the Capacitor Cordova compatibility layer:
npm install cordova-plugin-example
npx cap sync
Capacitor includes Cordova compatibility, but:
You can run Cordova and Capacitor side-by-side during migration.
When ready, remove Cordova entirely.
cordova plugin listnpm install @capacitor/plugin-namedeviceready event listenersnpx cap syncCapacitor enables instant updates without app store review.
After migration, add Capgo for OTA updates:
# Install Capgo plugin
npm install @capgo/capacitor-updater
# Create account at capgo.app
npm install -g @capgo/cli
capgo login
# Initialize and deploy
capgo init
npm run build
capgo upload
Users get updates instantly. See the capgo-live-updates skill for details.
| App Size | Estimated Time |
|---|---|
| Small (1-3 plugins) | 2-4 hours |
| Medium (4-8 plugins) | 1-2 days |
| Large (9+ plugins) | 3-5 days |
| Enterprise (custom plugins) | 1-2 weeks |
After migrating from Cordova to Capacitor:
✅ Faster development - Direct access to Xcode/Android Studio ✅ Live updates - Deploy updates without app store review (with Capgo) ✅ Better TypeScript - Full type safety ✅ Modern APIs - Promise-based, async/await ✅ Active maintenance - Regular updates and improvements ✅ Better debugging - Native IDE debugging tools ✅ Improved performance - Optimized native bridge
capacitor-ci-cd skill)capgo-live-updates skill)capacitor-app-store skill)Weekly Installs
51
Repository
GitHub Stars
20
First Seen
Feb 13, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
gemini-cli50
codex49
opencode49
github-copilot48
amp47
kimi-cli47
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
125,600 周安装
npm install @capacitor/status-bar| cordova-plugin-splashscreen | @capacitor/splash-screen | npm install @capacitor/splash-screen |
| cordova-plugin-keyboard | @capacitor/keyboard | npm install @capacitor/keyboard |
| cordova-plugin-dialogs | @capacitor/dialog | npm install @capacitor/dialog |
| cordova-plugin-file | @capacitor/filesystem | npm install @capacitor/filesystem |
| cordova-plugin-inappbrowser | @capacitor/browser | npm install @capacitor/browser |
| cordova-plugin-media | @capacitor/media | Custom or use @capgo plugins |
| cordova-plugin-vibration | @capacitor/haptics | npm install @capacitor/haptics |
| cordova-plugin-local-notifications | @capacitor/local-notifications | npm install @capacitor/local-notifications |
| cordova-plugin-push | @capacitor/push-notifications | npm install @capacitor/push-notifications |