pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
678 stars 103 forks source link

android: fix build #48

Closed Vinschni closed 11 months ago

Vinschni commented 1 year ago

I assume that line testedPaths.push_back(assetPath); is a residual from tests. It breaks android build.

 /home/vin/git/hello_imgui/build_android/hello_imgui_demodocking_AndroidStudio/app/jni/hello_imgui_subrepo/src/hello_imgui/internal/hello_imgui_assets.cpp:179:9: error: use of undeclared identifier 'testedPaths'
          testedPaths.push_back(assetPath);
          ^
  1 error generated.
  ninja: build stopped: subcommand failed.
pthom commented 1 year ago

Hi,

Thanks for pointing this out. I pushed a commit that removes this line. As I do not own an Android device anymore, I'd be interested in knowing whether the build succeeds for you :-)

Vinschni commented 1 year ago

I managed to build through hello_imgui_demodocking_AndroidStudio and generate "app-release-unsigned.apk" and "app-debug.apk".

Installation of "app-release-unsigned.apk" fails (package invalid) Instllation of "app-debug.apk" succeeds but on start I get an error due to missing hidapi lib. Its not build or linked in the cmake or project at any time.

Screenshot_2023-03-11-13-56-29-22_2a8a4a6083dfd5a730f68146f2d23811

pthom commented 1 year ago

Could you try to link it manually. For example with something like

target_link_libraries(hello_imgui_demodocking PRIVATE hidapi)
Vinschni commented 1 year ago

I added hidapi as submodule in ./external and tried to make cmake build recognize it by building and linking it.

Then i tried two ways. [1] Way

find_package(hidapi)
target_link_libraries(${target_name} hidapi )

after this line

but it does not find the folder... I tried to help it with

add_library(hidapi ${PROJECT_SOURCE_DIR}/../external/hidapi) 

but it does not work.

[2] Way I added after this line

set(HIDAPI_WITH_LIBUSB FALSE) # surely will be used only on Linux
set(BUILD_SHARED_LIBS FALSE) # HIDAPI as static library on all platforms
add_subdirectory(external/hidapi)

which gives me

--   No package 'libusb-1.0' found
CMake Error at /usr/local/share/cmake-3.20/Modules/FindPkgConfig.cmake:556 (message):
  A required package was not found
Call Stack (most recent call first):
  /usr/local/share/cmake-3.20/Modules/FindPkgConfig.cmake:778 (_pkg_check_modules_internal)
  external/hidapi/libusb/CMakeLists.txt:15 (pkg_check_modules)

I tried more things but don't get it to find and build that lib before trying to link it...

pthom commented 1 year ago

May be you could try to run without hidapi by commenting this line https://github.com/pthom/hello_imgui/blob/a6c6ffe4637885be23993938cef35be77c65d77b/hello_imgui_cmake/android/apkCMake/templates/sdl/apkCMake_activityClassName.java.in#L19 in hello_imgui_cmake/android/apkCMake/templates/sdl/apkCMake_activityClassName.java.in

edcarllos commented 11 months ago

First of all, congratulations on the project. I'm trying to run the demo projects for execution in an Android environment and have some problems.

I solved the first problem; in this case, the C++ version must be 17 because of the functional library. So I added this manually to CMakeLists in the Android Studio project and managed to get around it ["set(CMAKE_CXX_STANDARD 17)"].

On the other hand, I had the following problem: "unable to find library -lX11". I solved it by removing the call to the library from the configuration files.

Lastly, I came across this error regarding HIDAPI. I used the solution you suggested, and the error message mentioned above disappeared; however, the application does not open.

I'm running the project on a machine with Ubuntu 22.04. I'm available to help test some solutions. Thanks!

pthom commented 11 months ago

I'm sorry, I do not have an android device; so that it is difficult for me to run tests.

Could you try to run the application in a debugger and see where it stops or fails?

edcarllos commented 11 months ago

Thanks for the quick response. I tried running with Debug and got some information, but I wonder if it helped. To make it easier, I will post the photo with the execution in Android Studio. I highlighted the line where the error occurs.

Screenshot from 2023-12-14 20-43-48

pthom commented 11 months ago

I pushed some commits concerning Android. The build should now work directly. However, the app launches but shows nothing...

The solution should be somewhere inside https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md

pthom commented 11 months ago

Apps now work under Android. They do not use the icon provided in assets/app_settings at the moment

pthom commented 11 months ago

Everything should be ok under Android now:

image

See docs about android setting customization: https://github.com/pthom/hello_imgui_template/

pthom commented 11 months ago

@edcarllos : can you please test on your side

edcarllos commented 11 months ago

@edcarllos : can you please test on your side

Wow! Works like a charm! Thanks Pascal!

The only project that wasn't work was "hello_imgui_demo_test_engine_AndroidStudio" but I guess it is because I need to compile with the option "-DHELLOIMGUI_WITH_TEST_ENGINE=ON"

I had to do just two little modifications in build instructions to work perfectly. When executing the script "../tools/android/cmake_arm-android.sh" is necessary to add the above folder as parameter (../tools/android/cmake_arm-android.sh ../). Furthermore, the variable "HELLOIMGUI_CMAKE_PATH" was not set correctly, so I added the command "set(HELLOIMGUI_CMAKE_PATH /home/users/Projects/CLion/hello_imgui/hello_imgui_cmake)" in the file hello_imgui_add_app.cmake and worked.

Again, thanks for the quick response. Now I will try to analyze how to enable the virtual keyboard in an Android environment to allow text editing in applications.

pthom commented 11 months ago

Thanks!

The only project that wasn't work was "hello_imgui_demo_test_engine_AndroidStudio" but I guess it is because I need to compile with the option "-DHELLOIMGUI_WITH_TEST_ENGINE=ON"

I think so. It might not work out of the box on android, since ImGui Test Engine requires threading.

is necessary to add the above folder as parameter (../tools/android/cmake_arm-android.sh ../)

Corrected, thanks!

the variable "HELLOIMGUI_CMAKE_PATH" was not set correctly

I'm working on related aspects now.

enable the virtual keyboard in an Android environment

SDL_StartTextInput might help

If you get something working, and have time to post an example or a screenshot, please do it (I just opened a gallery).

edcarllos commented 11 months ago

SDL_StartTextInput might help

If you get something working, and have time to post an example or a screenshot, please do it (I just opened a gallery).

Thanks for the tip. If something works I will post it here. If you need to test any other functionality in an Android environment, I am also available.