...

Enhancing Cross-Platform Mobile Apps with Node.js Mobile, Ionic, and SQLite3

May 13, 2024

By Jamal Robinson

...

At Janea Systems, we're no strangers to Node.js's intricacies. After all, we've been maintaining Node.js on Windows for over a decade. As champions of interoperability, we also built and maintained Node.js for Mobile for many years before taking a step back and leaving it in the hands of the open source community.

In 2018, we introduced native modules into Node.js for Mobile Apps, significantly enhancing the framework. However, the need for updated solutions becomes crucial as technology rapidly evolves.

So, when a client providing government-related geolocation services encountered issues integrating the SQLite3 native module using the Cordova plugin in their mobile application development, they naturally turned to us. Read on to learn how we tackled their challenge and implemented solutions for Android and iOS in less than a week, enhancing the functionality and laying the groundwork to help unblock other native modules on nodejs-mobile.

If You Didn't Know

Here are a few brief descriptions of some of the technical aspects of this article:

Node.js:

Node.js is a versatile, open-source JavaScript runtime environment that supports multiple platforms including Windows, Linux, Unix, and macOS. Powered by the V8 JavaScript engine, it enables the execution of JavaScript code outside of web browsers. Node.js lets developers use JavaScript to write command-line tools and for server-side scripting.

Nodejs-mobile-gyp:

A fork of node-gyp we've tailored for mobile to ensure apps run smoothly across devices.

Cordova:

An open source framework that lets developers build mobile apps using web technologies.

SQLite3:

A lightweight database system used in our mobile app projects to provide robust data management without the overhead of larger databases.

The Challenge: Native Models like SQLite3 on Node.js Mobile

The client wanted to leverage SQLite3, a native module, within their mobile applications developed using Node.js Mobile. The project began by tackling Android-related challenges before expanding to iOS. Native modules are essential for direct system interactions in npm ecosystems but pose significant challenges in mobile environments due to differing operating systems and environment requirements.

Key Challenges:

Cross-Compilation: Native modules like SQLite3 are typically compiled at installation on desktops, but mobile apps require these modules to be cross-compiled and bundled within the app.

Environment Inconsistencies: Different build tools and environments between iOS and Android platforms introduced additional layers of complexity.

In essence, the problem was that SQLite3's build process helper was bypassing our custom Node.js mobile build tool (node-mobile-gyp), intended for mobile platforms, and instead using the standard desktop-oriented version. The module attempted to compile for desktop environments rather than mobile, leading to failures when deployed on mobile devices.

The Solution: Solving Mobile SQLite3 Challenges with Node.js and Cordova

Addressing these challenges required a multi-faceted approach tailored to each mobile platform's specifics:

Comprehensive Build Tool Adaptations:

We updated the nodejs-mobile-gyp tool to align with the latest node-gyp version 10.0.1 which supports Python 3. Although this wasn't a requirement for the client's SQLite 3 problem, the transition from deprecated Python 2 simplifies the development environment, streamlining builds and integrations across mobile platforms.

Platform-Specific Adaptations:

Android:

We addressed critical path resolution issues where the nodejs-mobile-cordova fork did not correctly locate nodejs-mobile-gyp, essential for properly compiling SQLite3. This was amended to ensure that the Android build environment was accurately configured.

iOS:

The community-maintained fork of the Node.js Mobile Cordova plugin had previously disabled iOS support. We reinstated iOS functionality, updated Node.xcframework to version 18.7.1, and made necessary adjustments to helper scripts for cordova-ios version 7+. This enabled developers to build and deploy on Apple devices again and allowed compilation on newer M series processors.

System-Wide Updates:

Node.js Mobile Cordova Plugin:

We addressed path resolution issues and adapted the plugin to meet the latest development standards. This update ensured smoother integration of native modules into the development workflow, enhancing developer productivity and reducing setup complications. By directing the build process correctly for mobile platforms, we made the plugin more reliable and functional in varied mobile development scenarios.

Fork and Dependent Management Enhancements:

Instructed customers how to override dependencies of dependencies through their package.json files to consume the fixes from our forks.

Community and Open Source Contributions:

These system-wide updates and platform-specific adaptations were shared with the open-source community through pull requests, encouraging feedback and further enhancements from developers worldwide. By openly collaborating on these developments, we ensured that our solutions would benefit our client and the broader development community, fostering improved functionality and broader application of the Node.js Mobile framework.

View our work on GitHub here and get involved:

Enabling nodejs-mobile-gyp for improved Node.js Mobile build process

https://github.com/mapbox/node-pre-gyp/pull/704

Improving nodejs-mobile-gyp resolution to build native modules on ionic and Cordova

https://github.com/okhiroyuki/nodejs-mobile-cordova/pull/61

Aligning nodejs-mobile-gyp with node-gyp 10.0.1

https://github.com/nodejs-mobile/nodejs-mobile-gyp/pull/2

iOS support for nodejs-mobile-cordova:

https://github.com/okhiroyuki/nodejs-mobile-cordova/pull/63

Support for prebuilt modules for nodejs-mobile-cordova:

https://github.com/okhiroyuki/nodejs-mobile-cordova/pull/73

Conclusion

We encourage you to join our efforts by contributing to the Node.js Mobile project and collaborating with us to pioneer new solutions that will shape the future of mobile app development. Together, let's build powerful, cross-platform mobile apps that bring desktop-level capabilities to the palm of your hand.

To learn more about how we help solve the trickiest software engineering problems, contact us here.

Meet the Software engineers who worked on this project:

Jaime Bernardo

Denis Bogomolov

Adam Kaczmarek

Related Blogs

Let's talk about your project

113 Cherry Street #11630

Seattle, WA 98104

Janea Systems © 2024

  • Memurai

  • Privacy Policy

  • Cookies

Let's talk about your project

Ready to discuss your software engineering needs with our team of experts?

113 Cherry Street #11630

Seattle, WA 98104

Janea Systems © 2024

  • Memurai

  • Privacy Policy

  • Cookies

Show Cookie Preferences