It might be the ordering of the commands, as you can see there is a commented out version higher up that I was experimenting with. Try modifying that entire section to this
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
int result = ANativeWindow_setBuffersGeometry(engine->app->window, WIDTH, HEIGHT, format); // change WIDTH and HEIGHT
LOGW( "Result: %d", result );
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
while ( surface == EGL_NO_SURFACE )
{
LOGW( "Failed to create EGL surface: %d, trying different format", eglGetError() );
formatIndex++;
if ( formatIndex >= numConfigs || formatIndex > 19 )
{
LOGW( "Failed to find compatible format" );
return -1;
}
config = allConfigs[ formatIndex ];
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
}
/* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
* guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
* As soon as we picked a EGLConfig, we can safely reconfigure the
* ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
//eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
//int result = ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);
//LOGW( "Result: %d", result );