I've been debating on whether or not to write this post for a few months now but I think it's time. I've decided to put the cross-platform apps with C development series on hold indefinitely. This year has of course been crazy with the covid-19 quarantine and social justice movements, but I also moved to a different country with my wife and we have a new addition to the family! In light of all of this, I've had my priorities shift quite a bit, and with my reduced time and desire to work on this, I don't see it coming to the close I had imagined when I started. I'll give a quick rundown of what little progress I had made before closing this chapter however.
I decided to use my Pi-helper app as a guinea pig of sorts since it's a fairly simple app to begin with. It takes in a server URL and password, saves them to disk, and then reads them to make network requests for a small set of predefined actions with little variability between each action. I originally wrote this app as a native app for both Android and iOS (you can read the details in the blog post I linked to above), so I have two different codebases to maintain now: one in Swift and one in Kotlin. As a result, I end up having to make any new changes twice: once in Swift and again in Kotlin. I thought it would be a lot easier to just share the logic for storing the connection details and making the network requests in C, so then I'd only have to worry about the UI and navigation for each platform in its native language. I started off by writing a C library with a simple command line interface, which allowed me to iterate on it quickly from my desktop. That ended up being quite helpful in the long run. With that in place, I actually did get a working implementation of this on Android, which you can see in the libpihelper branch of the project. The hardest part wasn't getting my code to compile but actually getting the handful of dependencies I needed (curl, openssl, and json-c) to compile for the most popular Android architectures. I had to do a lot of digging around to find people who had worked on scripting the build process for curl and openssl, and while I regrettably don't have the sources to properly attribute those scripts that helped guide me to getting a working solution, I have the script I ended up with in case it's useful to anyone else.
Getting the code to compile on iOS was a different story though. I ran into lots of issues with signing the code to be able to package it up as a convenient library I could include in the main project. I'm admittedly not very knowledgeable about Xcode nor its build process so I found this considerably more difficult than getting it to work on Android. Ultimately this is where I drew the line on how much time it was worth to invest in making it work. Perhaps if I had more time and energy to continue on this or if I had someone who was more knowledgable with iOS to assist me with the compilation of the library for iOS, I could have pulled through and wrapped it up, and I may finish that someday on my own, but for now I have other things to worry about.
I may have been a bit over-ambitious and perhaps even arrogant in the face of both Airbnb and Dropbox giving up on their respective cross-platform code sharing solutions, but I thought it would be fun to try something a little different. I think I ran into a lot of issues for quite a simple app, and trying to build anything more complex would have likely been a nightmare. Ultimately, I've found myself coming to the same conclusion that Dropbox did in their blog post:
[The overhead of sharing code between Android and iOS] ended up being more expensive than just writing the code twice.
For now, I'll stick with mostly Android development and dabble a little in iOS here and there when I need to scratch an itch. Happy coding!