Im trying build a step counter for android and im using expo and react-native-health-connect.
this is my code to request for permission:
useEffect(() => {
if (Platform.OS !== "android") {
return;
}
const init = async () => {
// initialize the client
const isInitialized = await initialize();
if (isInitialized) {
const grantedPermissions = await requestPermission([
{ accessType: "read", recordType: "Steps" },
]);
console.log({ grantedPermissions });
setAndroidPermissions(grantedPermissions);
}
};
init();
}, []);
But the code above gives me this error:
ERROR Your app just crashed. See the error below.
kotlin.UninitializedPropertyAccessException: lateinit property requestPermission has not been initialized
dev.matinzd.healthconnect.permissions.HealthConnectPermissionDelegate.launch(HealthConnectPermissionDelegate.kt:32)
dev.matinzd.healthconnect.HealthConnectManager$requestPermission$1$1.invokeSuspend(HealthConnectManager.kt:64)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)
What are the causes and fix for this issue?
I’ve been using this guides to implement this feature:
- https://github.com/matinzd/react-native-health-connect?tab=readme-ov-file#expo-installation
- https://www.notjust.dev/projects/step-counter/android-health-connect#react-native—android-health-connect-integration