Android backend build error: ALooper_pollAll has been deprecated on Android NDK Version 27
Version/Branch of Dear ImGui:
Version 1.90, Branch: master
Back-ends:
imgui_impl_android.cpp + imgui_impl_opengl3.cpp
Compiler, OS:
Android Studio with NDK version 27.1.12297006
Full config/build information:
No response
Details:
D:\Android\Sdk\ndk\27.1.12297006\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android24 --sysroot=D:/Android/Sdk/ndk/27.1.12297006/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DIMGUI_IMPL_OPENGL_ES3 -DImGuiExample_EXPORTS -ID:/imgui-1.90/examples/example_android_opengl3/../.. -ID:/imgui-1.90/examples/example_android_opengl3/../../backends -ID:/Android/Sdk/ndk/27.1.12297006/sources/android/native_app_glue -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-limit-debug-info -std=c++11 -fPIC -MD -MT CMakeFiles/ImGuiExample.dir/main.cpp.o -MF CMakeFiles\ImGuiExample.dir\main.cpp.o.d -o CMakeFiles/ImGuiExample.dir/main.cpp.o -c D:/imgui-1.90/examples/example_android_opengl3/main.cpp
D:/imgui-1.90/examples/example_android_opengl3/main.cpp:98:16: error: 'ALooper_pollAll' is unavailable: obsoleted in Android 1 - ALooper_pollAll may ignore wakes. Use ALooper_pollOnce instead. See The API documentation for more information
98 | while (ALooper_pollAll(g_Initialized ? 0 : -1, nullptr, &out_events, (void**)&out_data) >= 0)
| ^
D:/Android/Sdk/ndk/27.1.12297006/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/android/looper.h:228:5: note: 'ALooper_pollAll' has been explicitly marked unavailable here
228 | int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData)
| ^
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
MoreCodeToExplainMyIssue();
ImGui::End();
Just change the called API from ALooper_pollAll to ALooper_pollOnce,and it works well.
I have pushed the suggested change as f77d228. Thank you!
@ocornut bumped into this. Theorically, the fix could be incorrect, as per documentation Calls to ALooper_pollAll() should be replaced with ALooper_pollOnce(). If you call ALooper_pollOnce() in a loop, you must treat all return values as if they also indicate ALOOPER_POLL_WAKE.
Looking at other repos, they changed the >= to > ALOOPER_POLL_TIMEOUT This is because ALOOPER_POOL_WAKE (-1) and ALOOPER_POOL_CALLBACK (-2) still indicate we should continue the loop. So > ALOOPER_POLL_TIMEOUT (-3) is technically the correct test.
Can reopen this or create a new issue with PR