How we built our own Google Fit SDK integration for React Native

2 mins read by Varchasvi Pandey

Google Fit SDK by Alyve Health

Getting to understand React Native's complex architecture to implement core native modules is so essential as it unlocks a lot of opportunities to develop something powerful and flexible. This blog post is about our journey at Alyve Health to make a fully functional, robust integration of Google Fit SDK.

Background

In the last four years (2020-2024), we have encountered many possible ways of integrating Google Fit to fetch user KPIs. Being the web-first platform, our first best solution was implementing Google Fitness API with a combination of Google OAuth 2 authentication. It turned out to be a very stable solution for us for all the platforms we were targeting but this RESTful implementation was unable to provide us with real-time KPI updates.

Consuming React Native packages for Google Fit

Our Android and iOS applications, being built on React Native, share a common codebase that allows us to maintain our applications better. We started looking for some packages built for React Native to use the real-time Google Fit features. We indeed found some but with too many flaws. Some features seemed to be working correctly but were giving us unexpected issues and inaccurate data most of the time. Finally, we took a call to create our native implementation of Google Fitness SDK for React Native. The spoiler here is that it worked, and it worked perfectly.

What we did to create our own Google Fit Module

Since our application is built on Expo, we used Expo Modules API, which is amongst the most intimidating APIs by Expo for web developers who got into native development with React Native. This API requires core native code on Kotlin and Swift. It was easy to know and leverage the fact that we didn't have to set up a complete Kotline project to create this custom module. So we broke down our module development into the following steps:

  1. Creating a list of functionalities.
  2. Understanding user/device permissions required to build those functionalities.
  3. Creating interfaces to make the Kotlin exported functions work well in both the Kotlin environment as well as React Native environment ensuring 100% type safety.
  4. Making use of our very own native module after creating an Android development build.
  5. Testing everything by giving critical attention to one of the main features i.e. real-time KPI syncing.

Conclusion

React Native is often considered a technology that is not meant to be used for applications using core native modules like sensors. But as this technology is growing, it is opening numerous possibilities to achieve almost everything. Our call at Alyve Health to move out from Kotlin & Swift to fully adopt React Native for building our application considered these inevitable challenges. And just like many other features, this feature gradually kept on getting better implemented by us. We are further working on this to make it even better with the new Google Health Connect! Keeping the technology spirit up at Alyve Health 🔥