backport of ndk/commits/113d4c56180b8f59cb03d738f76dab46dd7fafe0 (cherry picked from commit 0aa12867)