82 points · by luu · 9y ago · 53 comments
sqlite.so isn't part of public Android API surface, which means the OEMs will regularly replace it, break it, compile it with strange options and deal a lot of pain to you and your users.
So if you weren't shipping your own native SQLite in NDK/Xamarin you already had problems, you just maybe didn't notice them.
Android N is now actually actively preventing linking against system libraries which aren't part of public API surface, which is good - it'll result in less developers doing dumb things which break on minor updates.
You can never stop the Facebook developers doing dumb things on Android.
Google have tried for years, but Facebook always manages to find new ways to fuck up.
https://www.facebook.com/notes/facebook-engineering/under-th...
Xamarin, Cordova and others are pretty much a cesspool of catastrophically poor libraries so I'm not sure why Google has to take the blame for that.
Why is the NDK so underpowered? Why are they so reluctant (or unable) to publish some useful, stable native APIs? It's missing things like curl, sqlite, icu, OpenSSL. Most of these are built into the OS but not accessible via the NDK. (OpenSSL isn't a great library, I know, but it's patchable. And they could start now with something better.)
The only useful native third-party libraries you get are: zlib, OpenGL ES, OpenSL ES.
Apart from that, there are a bunch of wrappers for a small subset of Java APIs (AssetManager, Bitmap and so on). These are tedious to use, and seem to have been written by hand so in some cases they're buggy -- for example, incorrect string handling in AStorageManager: https://code.google.com/p/android/issues/detail?id=41983
NDK team doesn't look like it's expansive or prioritized at all, so I doubt they have resources or will to do that. TBH I'd rather they focus at improving the tooling and debugging, we can ship our own libraries with our own options compiled in. Heck even on iOS we have to ship a custom SQLite to get all the needed capability.
Google has one of the largest software engineering populations of any company in the world. It supports one of the largest developer ecosystems in the world. Games are the largest catagory in their ecosystem. 2 engineers supporting the NDK...
Most likely due to game development community.
Specially when compared with the tooling support C and C++ enjoy on iDevices and UWP.
So anyone that wants 2D graphics from NDK side either needs to call into Java, or bring their own library on top of OpenGL.
And the whole mismanaged way how the C++ IDE and build system migration was handled.
What you want is stable APIs for things that interact in fiddly ways with the rest of the system, so they're more easily managed at the OS level. Networking, shared databases. (Edit to add: localization)
zlib is nice to have, but it's also really portable and lightweight. It would be easy for apps to bundle their own copies. Something like libcurl is a lot more awkward (what do you use for https? bundle your own SSL too!)
In any case that was just an example.
Android has nothing like Objective-C++ or C++/CX for easy interoperability with the OS APIs.
I bet many Android devices already have at least 9 copies of sqlite, since so many apps ship their own copy.
There are already implementations [1][2] of this, but because it is not provided by the Android team it is hardly supported by ORMs, libraries, etc.
[0] https://code.google.com/p/android/issues/detail?id=202658
The problem - from what I understand - is that you used to be able to use the systems sqlite.so to access databases owned by your app from the native environment. With Android N you are no longer able to do this, you need to ship your own sqlite binary.
This can lead to problems when you want to access the same sqlite files from both the Android platform APIs and native (e.g. use it from native for business logic, debug it with a tool like Stetho [0] that uses android.database.sqlite) because of a version mismatch.
Would Google offer (a copy of) the Android API with the ability to plug in a different sqlite-compatible binaries, it would very likely find broad adoption. Then the problem stated by the article could be solved by shipping the app with a sqlite build that is used by both the native code and plugged into the compat library.
SQLite was also shaking out a (very) few bugs out during this time period; pretty sure this auto-delete implementation wiped any chance of semi-easily recovering my first phone's SMS db.
https://stackoverflow.com/questions/7764943/what-can-be-done...
"8. Bugs in SQLite" (2013)
Does SQLite accept patches?
Though, my guess shouldn't stop you looking for previous suggestions to implement this, and if there are none, submitting it yourself :)
1. https://refspecs.linuxfoundation.org/LSB_4.0.0/LSB-Core-gene...
https://code.google.com/p/android/issues/detail?id=213433
Although I mentioned using dlopen and dlsym to find the SQLite functions in the current process, our actual production solution was to use JNI to call the android.database.sqlite classes.
You have no idea what version of sqlite the OS might be using, so you can't rely on consistent behavior. In many cases the vendor will have tinkered with it and messed it up. Comprehensively testing on all Android devices is basically impossible because there are so many models out there.