Ionic v4集成AppCenter CodePush遇更新回滚及cordova_not_available问题
Let's break down why you're seeing this rollback issue and how to fix it:
The Root Cause
The "Update ignored, because it was rollbacked" message happens because CodePush never receives confirmation that your app started successfully after the update. Your notifyApplicationReady() call is failing due to the "cordova_not_available" error, which means the Cordova runtime isn't fully initialized when you're trying to call CodePush methods.
Why "cordova_not_available" Happens in Your Setup
In your current code, you're calling notifyApplicationReady() and sync() in parallel right after platform.ready() fires. But platform.ready() only signals that the Ionic platform is ready—it doesn't guarantee that all Cordova plugins (including CodePush) are fully initialized yet. When using InstallMode.IMMEDIATE, the sync triggers an immediate app restart, and the new version might try to run CodePush methods before Cordova is fully ready.
Step-by-Step Fixes
1. Reorder Your Code to Prioritize notifyApplicationReady()
Make sure you confirm the app is ready to CodePush before checking for updates. Also, add a check to ensure you're only running CodePush operations in a Cordova environment (avoids web testing errors):
initializeApp() { this.platform.ready().then(() => { this.statusBar.styleDefault(); this.splashScreen.hide(); // Only run CodePush logic if we're in a Cordova environment if (this.platform.is('cordova')) { // First confirm app readiness to CodePush this.codePush.notifyApplicationReady() .then(() => { console.log('CodePush: App startup confirmed'); // Now trigger the sync after confirmation return this.codePush.sync({ deploymentKey: 'MY_KEY', installMode: InstallMode.IMMEDIATE }); }) .subscribe(status => { console.log('CodePush sync status:', status); }) .catch(err => { console.error('CodePush error:', err); }); } else { console.warn('Cordova not available—skipping CodePush operations'); } }); }
2. Fix Simulator-Specific Issues
Android emulators sometimes have caching or plugin initialization delays that cause false "cordova_not_available" errors:
- Delete the app from the emulator completely, then rebuild and reinstall it.
- Try testing on a physical Android device—emulators often have quirky behavior that doesn't reflect real-world usage.
- Clear the emulator's cache (go to Android Studio > AVD Manager > Select your emulator > Wipe Data).
3. Verify Plugin Installation
Double-check that the CodePush plugin is properly installed for your Cordova platform:
- Run
cordova plugin listto confirmcordova-plugin-code-pushis listed. - If it's missing, reinstall it with:
cordova plugin add cordova-plugin-code-push --save --variable CODEPUSH_DEPLOYMENT_KEY="MY_KEY" - Ensure your Ionic and CodePush plugin versions are compatible (for Ionic v4, use
cordova-plugin-code-push@latestor a version explicitly marked compatible with v4).
Why This Works
By calling notifyApplicationReady() first and waiting for it to resolve before triggering the sync, you ensure:
- The current app version confirms it started successfully to CodePush (preventing unnecessary rollbacks).
- When the immediate update restarts the app, the new version will run
notifyApplicationReady()first, telling CodePush the update was successful. - The Cordova environment check avoids errors when testing in a browser or non-Cordova context.
内容的提问来源于stack exchange,提问作者EinfachHans

