Meteor 1.8.1 Android应用HCP无法更新问题求助
Let's tackle your HCP update problems one by one, since they’re all interconnected:
1. Resolve Asset Manifest Parsing Error
The error Caused by: org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject makes it clear your app is receiving an HTML page (like a 404 error) instead of a valid JSON manifest from your server. This directly links to your later discovery of mismatched App IDs. Here’s how to fix it:
- Align App IDs Perfectly: Your Android app’s ID is defined in
config.xmlas theidattribute of the<widget>tag (e.g.,<widget id="com.your.app.id" ...>). Set your server’sAPP_IDenvironment variable to this exact string—typos or case differences will break matching. - Validate the Manifest Endpoint: Visit
http://your-server-url/__cordova/manifest.jsonin a browser. It should return a valid JSON object with asset hashes. If it returns HTML, your server’sAPP_IDis still misconfigured.
2. Fix Missing Cordova Resources
Logs showing missing /cordova.js, /cordova_plugins.js, and plugin files mean Meteor isn’t packaging Cordova assets into your HCP bundles. Let’s correct that:
- Ensure the WebApp Plugin is Installed: Run
meteor add cordova:cordova-plugin-meteor-webapp@1.9.0(this version is compatible with Meteor 1.8.1). This plugin manages HCP assets and update logic. - Rebuild Cleanly:
# Reset Cordova platform config meteor remove-platform android meteor add-platform android # Rebuild server with updated Cordova assets meteor build ../build-output --server your-server-url - Leave Auto-Generated Folders Alone: Never manually edit or delete the
__cordovadirectory—Meteor generates this automatically during builds, and tampering breaks resource mapping.
3. Fix mobile-config.js Failure in Meteor 1.8.1
Meteor 1.8.1 changed how mobile-config.js is handled compared to 1.4. Here’s the correct setup:
- File Location: Place
mobile-config.jsin your project root (same level as the.meteorfolder)—Meteor reads it automatically, so you don’t need to pass it via--mobile-settings(that flag is for JSON settings files, not this JS config). - Correct Syntax:
// mobile-config.js App.info({ id: 'com.your.app.id', // Must match config.xml's widget ID and server APP_ID name: 'Your App Name', version: '1.0.0' }); // Configure HCP behavior App.configurePlugin('cordova-plugin-meteor-webapp', { update: 'auto', // Auto-check for updates on app start; use 'none' for manual control minimumBackgroundDuration: 30 // Optional: Wait 30s in background before applying updates }); - Rebuild After Changes: After updating
mobile-config.js, re-run the platform removal/addition and build commands to apply the new config.
4. Ensure HCP Update Logic Works Correctly
Even with correct configuration, you might need to adjust how you trigger updates:
- Wait for
deviceready: Cordova plugins (including HCP) aren’t initialized until thedevicereadyevent fires. Wrap your manual update check in this event:Meteor.startup(() => { document.addEventListener('deviceready', () => { // Check for updates manually WebAppLocalServer.checkForUpdates((error, updateAvailable) => { if (error) { console.error('HCP Check Failed:', error); return; } if (updateAvailable) { // Apply update and reload WebAppLocalServer.applyUpdate(() => { console.log('Update applied—restarting app'); location.reload(); }); } }); }, false); }); - Verify Auto-Update: If you set
update: 'auto'inmobile-config.js, the app should automatically check for updates on startup and apply them in the background (based on yourminimumBackgroundDurationsetting).
5. Fix Uninstall/Reinstall Not Reflecting Updates
If uninstalling and reinstalling doesn’t pull the latest content, it’s likely a caching issue:
- Clear Server Cache: Restart your Meteor server to ensure it’s serving the latest manifest and assets.
- Clear App Storage: On Android, go to Settings > Apps > Your App > Storage > Clear Storage + Clear Cache, then reinstall.
- Validate Server Assets: Check the
assets/app/manifest.jsonfile in your Meteor server build output to confirm the hashes match your updatedpublicfolder content.
内容的提问来源于stack exchange,提问作者oazabir

