乐闻世界logo
搜索文章和话题

How does Expo's OTA update work? How to use EAS Update?

2月21日 16:02

Expo's OTA (Over-the-Air) update feature allows developers to push app updates without resubmitting to app stores. This is a powerful feature that can significantly speed up iteration.

OTA Update Principle:

Expo OTA works by uploading the JavaScript bundle and asset files to Expo servers, then checking and downloading updates when the app starts.

Workflow:

  1. Developer uses eas update command to upload updates
  2. Expo server stores updates and assigns unique version numbers
  3. App checks server for new versions on startup
  4. If new version exists, download and apply update
  5. Users see updated content next time they open the app

EAS Update Usage:

  1. Install EAS CLI:
bash
npm install -g eas-cli
  1. Configure Project:
bash
eas build:configure
  1. Create Update:
bash
# Create and publish update eas update --branch production --message "Fix login bug" # Specify runtime version eas update --branch production --runtime-version 1.0.0 # Preview update eas update --branch preview --message "Test new feature"
  1. View Update History:
bash
# View all updates eas update:list # View updates for specific branch eas update:list --branch production
  1. Rollback Update:
bash
# Rollback to previous version eas update:rollback --branch production # Rollback to specific version eas update:rollback --branch production --target-message "Previous stable version"

Configure app.json:

json
{ "expo": { "updates": { "url": "https://u.expo.dev/your-project-id" }, "runtimeVersion": { "policy": "appVersion" } } }

Runtime Version Policies:

Expo supports multiple runtime version policies:

  1. appVersion Policy (Recommended):
json
{ "runtimeVersion": { "policy": "appVersion" } }
  • Uses app version as runtime version
  • Simple and direct, suitable for most scenarios
  1. nativeVersion Policy:
json
{ "runtimeVersion": { "policy": "nativeVersion" } }
  • Uses native code version
  • More precise control
  1. customVersion Policy:
json
{ "runtimeVersion": { "policy": "customVersion", "customVersion": "1.0.0" } }
  • Custom version number
  • Maximum flexibility

Update Groups:

Create different update branches to manage updates for different environments:

bash
# Production environment update eas update --branch production # Preview environment update eas update --branch preview # Development environment update eas update --branch development

Client Configuration:

typescript
import * as Updates from 'expo-updates'; // Check for updates async function checkForUpdates() { try { const update = await Updates.checkForUpdateAsync(); if (update.isAvailable) { await Updates.fetchUpdateAsync(); Updates.reloadAsync(); } } catch (error) { console.error('Error checking for updates:', error); } } // Manually trigger update check checkForUpdates(); // Listen to update events Updates.addListener(event => { if (event.type === Updates.UpdateEventType.UPDATE_AVAILABLE) { console.log('Update available:', event); } });

Limitations and Considerations:

  1. Only JavaScript and assets can be updated: Cannot update native code

  2. App Store Review: Some app stores have policy restrictions on OTA updates

  3. Version Compatibility: Updates must be compatible with current runtime version

  4. Network Dependency: Users need network connection to receive updates

  5. Rollback Mechanism: Need to implement rollback strategy for problematic updates

Best Practices:

  1. Gradual Rollout: Test updates with small group of users first

  2. Version Management: Maintain clear version numbers and update logs

  3. Error Monitoring: Monitor error rates after updates

  4. User Notification: Notify users before updates

  5. Rollback Preparation: Be ready to rollback to stable version anytime

  6. Test Coverage: Thoroughly test updates before release

Common Issues:

  1. Updates Not Taking Effect: Check if runtime versions match

  2. Update Failures: Check server logs and client errors

  3. Performance Impact: Monitor impact of update downloads on app performance

  4. Security Considerations: Ensure update transmission uses HTTPS encryption

Expo OTA updates are an important tool for rapid app iteration, and proper use can greatly improve development efficiency and user experience.

标签:Expo