This is how I connect QField to PostGIS on Android phone using the connection service file:
First, on Windows PC, create file
.pg_service.conf to store login information. My file looks like this:
Use Notepad++ to convert end-of-line characters to Unix style as described in Qgis documentation and save in
C:\Users\MyUsername\AppData\Roaming\postgresql - you may have to create the folder
Second, open Qgis and creat a new project, create a new connection to PostgreSQL using menu
layer > Add layer > Add PostGIS Layer > new. I filled out the opened form as follow:
name field could be whatever name you want to call your new connection and the
service field should be the same as the first line in your
.pg_service.conf file, minus the brackets - in this case it should be
Data Source Manager | PostgreSQL form, choose your newly created connection and click
Connect - you should be able to connect to your Postgis database and see your layers listed - add any layer you want.
Save your project using
.qgs format - you are about to achieve your aim of working with Postgis layers on Android phone using QField.
Create a copy of your
.pg_service.conf, rename it to
pg_service.conf (remove the first dot in the name) and ship to your Android phone - remember to put it in the folder
Finally, ship the above
.qgs project to your phone, open it with QField and enjoy!