Cordova应用快捷方式插件问题:Android构建失败及iOS替代方案咨询
Hey there! Sorry to hear you're stuck with the cordova-plugin-shortcuts-android build failure—even after updating your Android SDK. Let's break down reliable alternatives for both Android and iOS, plus a quick note on why the original plugin might be misbehaving.
Android替代插件
Here are two well-maintained options that play nicer with modern Cordova and Android SDK versions:
1. cordova-plugin-app-shortcuts
This plugin supports both static and dynamic app shortcuts (compatible with Android 7.1+) and aligns smoothly with Cordova's latest tooling.
- Install it with:
cordova plugin add cordova-plugin-app-shortcuts - Example of creating a dynamic shortcut:
cordova.plugins.shortcuts.add({ id: "open-settings", shortLabel: "Settings", longLabel: "Open App Settings", icon: "res://ic_settings", intent: "intent://settings#Intent;scheme=myapp;package=com.your.app;end" }, function() { console.log("Shortcut added successfully"); }, function(error) { console.error("Failed to add shortcut:", error); });
2. Custom Native Wrapper (For Full Control)
If off-the-shelf plugins don't cover your specific needs, you can wrap Android's native ShortcutManager API into a tiny custom Cordova plugin. This lets you leverage newer Android features (like Android 12+ shortcut styling) without relying on third-party code.
iOS同类插件
For iOS Home Screen Quick Actions (the equivalent of Android app shortcuts), these plugins work seamlessly:
1. cordova-plugin-3dtouch
The most widely used option for iOS quick actions, supporting both static (configured in config.xml) and dynamic shortcuts. It works with Haptic Touch (newer iPhones) and legacy 3D Touch.
- Install it with:
cordova plugin add cordova-plugin-3dtouch - Example of adding a dynamic quick action:
if (window.plugins && window.plugins.ThreeDeeTouch) { window.plugins.ThreeDeeTouch.addQuickAction({ type: "open-favorites", title: "Favorites", subtitle: "View your saved items", iconType: "Favorites" }); } - To add static quick actions, add this to your
config.xml:<platform name="ios"> <config-file parent="UIApplicationShortcutItems" target="*-Info.plist"> <array> <dict> <key>UIApplicationShortcutItemType</key> <string>com.your.app.open-settings</string> <key>UIApplicationShortcutItemTitle</key> <string>Settings</string> <key>UIApplicationShortcutItemIconType</key> <string>UIApplicationShortcutIconTypeSettings</string> </dict> </array> </config-file> </platform>
2. cordova-plugin-quick-actions
A lightweight alternative focused solely on iOS quick actions, with a simplified API for dynamic shortcuts. Great if you don't need all the extra features of cordova-plugin-3dtouch.
Quick Debug Note for the Original Plugin
The cordova-plugin-shortcuts-android likely uses outdated Gradle configurations that clash with your project's Android SDK/Cordova Android version. If you still want to fix it, check the plugin's build.gradle file to ensure it uses a compatible Gradle plugin version (e.g., com.android.tools.build:gradle:7.0.0+ for Cordova Android 11+). But switching to one of the alternatives above is usually faster and more reliable.
内容的提问来源于stack exchange,提问作者Shashank HS

