  A simultaneous analysis of the $B^+\to K^+\ell^+\ell^-$ and $B^0\to
K^{*0}\ell^+\ell^-$ decays is performed to test muon-electron universality in
two ranges of the square of the dilepton invariant mass, $q^2$. The measurement
uses a sample of beauty meson decays produced in proton-proton collisions
collected with the LHCb detector between 2011 and 2018, corresponding to an
integrated luminosity of $9$ $\text{fb}^{-1}$. A sequence of multivariate
selections and strict particle identification requirements produce a higher
signal purity and a better statistical sensitivity per unit luminosity than
previous LHCb lepton universality tests using the same decay modes. Residual
backgrounds due to misidentified hadronic decays are studied using data and
included in the fit model. Each of the four lepton universality measurements
reported is either the first in the given $q^2$ interval or supersedes previous
LHCb measurements. The results are compatible with the predictions of the
Standard Model.
