This answer is about the physical origin of gravity.
It comes about due to the requirement that the universe should have scaling symmetry and the principle of conservation of energy.

If the universe were to rescale, then all physical constants and quantities with length dimensions would vary as in the table below, where $H$ is a scaling constant.
\begin{array}{c|c|c}
{quantity} & {length-dimension} & {change}\\
\hline
length & 1 & e^{Ht}\\
mass & 0 & constant\\
time & 0 & constant\\
h & 2 & e^{2Ht}\\
c & 1 & e^{Ht}\\
G & 3 & e^{3Ht}\\
Area & 2 & e^{2Ht}\\
\end{array}
Then imagine a mass $m$ of energy $mc^2$, it's energy changes to $mc^2e^{2Ht}$.
That's without gravity, however with gravity the total energy due to the mass is
$$mc^2 - \frac{GMm}{R}$$
Where $M$and $R$ represent the mass and radius of the universe up to the Hubble radius and small numerical constants are omitted for simplicity.
Then energy can be conserved as the universe rescales if
$$(mc^2 - \frac{GMm}{R})e^{2Ht} = 0$$
and $$G=\frac{Rc^2}{M}$$
That gives a reason for the value of $G$ and an explanation of the flatness problem.
The equivalent from General Relativity is
$$G=\frac{3H^2}{8\pi \rho}$$
i.e the universe is at critical density.
See also this link