marcomq / nimview

A Nim/Webview based helper to create Desktop/Server applications with Nim/C/C++ and HTML/CSS
MIT License
151 stars 11 forks source link

How do you compile, debug-run & deploy on android? #41

Open ItsCubeTime opened 1 year ago

ItsCubeTime commented 1 year ago

Hi 👋Cool project!

How do you compile, debug-run & deploy on android?

marcomq commented 1 year ago

Hi! I used android studio. There is an example project here: https://github.com/marcomq/nimview/tree/main/examples/android Unfortunately, there is no separate or easy cli command.

ItsCubeTime commented 1 year ago

How are you supposed to build it exactly?

image

Opening up https://github.com/marcomq/nimview/tree/main/examples/android in Android Studio and hitting build as in the screenshot I get the following log:

Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process C:\Users\olliv\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C C:\Users\olliv\Desktop\Art And Development\Nim Learning\nimview src\nimview\examples\android\app\.cxx\cmake\debug\armeabi-v7a native-lib}
  ninja: Entering directory `C:\Users\olliv\Desktop\Art And Development\Nim Learning\nimview src\nimview\examples\android\app\.cxx\cmake\debug\armeabi-v7a'
  [1/2] cmd.exe /C "cd /D "C:\Users\olliv\Desktop\Art And Development\Nim Learning\nimview src\nimview\examples\android\app\src\main\nim" && nake"
  No task specified, running default task defined by nakefile.
  [2/2] Linking CXX shared library "C:\Users\olliv\Desktop\Art And Development\Nim Learning\nimview src\nimview\examples\android\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so"
  FAILED: C:/Users/olliv/Desktop/Art And Development/Nim Learning/nimview src/nimview/examples/android/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so 
  cmd.exe /C "cd . && C:\Users\olliv\AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/olliv/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/olliv/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -std=c++17 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libnative-lib.so -o "C:\Users\olliv\Desktop\Art And Development\Nim Learning\nimview src\nimview\examples\android\app\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so" CMakeFiles/native-lib.dir/native-lib.cpp.o  -llog -latomic -lm && cd ."
  C:/Users/olliv/Desktop/Art And Development/Nim Learning/nimview src/nimview/examples/android/app/src/main/cpp/./nimview.hpp:33: error: undefined reference to 'NimMain()'
  C:/Users/olliv/Desktop/Art And Development/Nim Learning/nimview src/nimview/examples/android/app/src/main/cpp/./nimview.hpp:190: error: undefined reference to 'nimview_add_argc_argv_rstr'
  C:/Users/olliv/Desktop/Art And Development/Nim Learning/nimview src/nimview/examples/android/app/src/main/cpp/./nimview.hpp:228: error: undefined reference to 'nimview_dispatchRequest'
  C:/Users/olliv/Desktop/Art And Development/Nim Learning/nimview src/nimview/examples/android/app/src/main/cpp/./nimview.hpp:233: error: undefined reference to 'nimview_dispatchRequest'
  C:/Users/olliv/Desktop/Art And Development/Nim Learning/nimview src/nimview/examples/android/app/src/main/cpp/./nimview.hpp:238: error: undefined reference to 'nimview_enableStorage'
  C:/Users/olliv/Desktop/Art And Development/Nim Learning/nimview src/nimview/examples/android/app/src/main/cpp/./nimview.hpp:241: error: undefined reference to 'nimview_callJs'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::dispatchCommandLineArg: error: undefined reference to 'nimview_dispatchCommandLineArg'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::readAndParseJsonCmdFile: error: undefined reference to 'nimview_readAndParseJsonCmdFile'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::setCustomJsEval: error: undefined reference to 'nimview_setCustomJsEval'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_void: error: undefined reference to 'nimview_add'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_rstr: error: undefined reference to 'nimview_add_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_cstring: error: undefined reference to 'nimview_add_cstring'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_cstring_rstr: error: undefined reference to 'nimview_add_cstring_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_clonglong: error: undefined reference to 'nimview_add_clonglong'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_clonglong_rstr: error: undefined reference to 'nimview_add_clonglong_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_cdouble: error: undefined reference to 'nimview_add_cdouble'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_cdouble_rstr: error: undefined reference to 'nimview_add_cdouble_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::add_argc_argv_rstr: error: undefined reference to 'nimview_add_argc_argv_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_void: error: undefined reference to 'nimview_add'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_rstr: error: undefined reference to 'nimview_add_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_cstring: error: undefined reference to 'nimview_add_cstring'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_cstring_rstr: error: undefined reference to 'nimview_add_cstring_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_clonglong: error: undefined reference to 'nimview_add_clonglong'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_clonglong_rstr: error: undefined reference to 'nimview_add_clonglong_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_cdouble: error: undefined reference to 'nimview_add_cdouble'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_cdouble_rstr: error: undefined reference to 'nimview_add_cdouble_rstr'
  CMakeFiles/native-lib.dir/native-lib.cpp.o:native-lib.cpp:nimview::addRequest_argc_argv_rstr: error: undefined reference to 'nimview_add_argc_argv_rstr'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
ItsCubeTime commented 1 year ago

Im on Windows 11 if it makes any difference

marcomq commented 1 year ago

I also had this or a similar linker issue from time to time. No idea why. Had to perform a rebuilt and then it somehow worked again.