Expo Setup
The easiest way to use react-native-healthx is with Expo's config plugin system.
Prerequisites
- Expo SDK 49 or later
- Development build (not Expo Go)
Expo Go Not Supported
react-native-healthx uses native code and cannot run in Expo Go. You'll need to create a development build.
Installation
npx expo install react-native-healthx
Configuration
Add the plugin to your app.json or app.config.js:
app.json
{
"expo": {
"plugins": [
[
"react-native-healthx",
{
"healthSharePermission": "Allow $(PRODUCT_NAME) to read your health data",
"healthUpdatePermission": "Allow $(PRODUCT_NAME) to save your health data"
}
]
]
}
}
Plugin Options
| Option | Type | Description |
|---|---|---|
healthSharePermission | string | iOS permission message for reading health data |
healthUpdatePermission | string | iOS permission message for writing health data |
Generate Native Code
Run prebuild to generate the native projects:
npx expo prebuild
This will:
iOS
- Add HealthKit capability
- Add
NSHealthShareUsageDescriptionto Info.plist - Add
NSHealthUpdateUsageDescriptionto Info.plist - Configure HealthKit entitlements
Android
- Add
android.permission.health.READ_SLEEPpermission - Add
android.permission.health.WRITE_SLEEPpermission - Add Health Connect query package
- Add permissions rationale intent filter
Build
Create a development build:
# iOS
npx expo run:ios
# Android
npx expo run:android
Or use EAS Build:
eas build --profile development --platform all
Verify Setup
After building, verify the setup:
import HealthX from 'react-native-healthx';
async function verify() {
const status = await HealthX.checkAvailability();
console.log('Health available:', status.isAvailable);
console.log('Platform:', HealthX.getPlatform());
console.log('Supports write:', HealthX.supportsWrite());
}
Troubleshooting
"Health data not available"
- iOS Simulator: HealthKit is not available in the simulator. Test on a real device.
- Android Emulator: Install the Health Connect app from Play Store on the emulator.
"Module not found"
Make sure you've run npx expo prebuild after adding the plugin.
Permission denied after prebuild
Clear the native projects and rebuild:
npx expo prebuild --clean