androidc++android-ndklibpq

Is it possible to use postgresql libpq in android?


I'm developing an app using android ndk in c++.

How can I use the libpq library client in Android?
I'm unable to find the libpq for ARM, so, is it possible to compile it for ARM?

I tried using Visual Studio 2019 , I created a project to build an Android Library, and added the source from postgresql but the library fails to build as it seems to depend from winsock2 and such.

Is this the way? Do I need some preprocessor options I do not know?


Solution

  • Even if you can, you shouldn't. A mobile app should NEVER directly connect to a backend DB. Doing so would require you to have your password embedded in the app, with mininal obfuscation. This means anyone with rudimentary reverse engineering skills can break it down and find the password, giving them total control over your data.

    Instead, what you should do is have a web service between your app and the db. All requests go to the webservice. That service authenticates the user, and the password for the db is stored on the server, so it never leaves your control. This minimizes the damage a malicious user can do to your infrastructure.