diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index a1507f46e..0503257e1 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -22,6 +22,8 @@ #ifndef VCMI_ANDROID #include "../lib/Interprocess.h" +#else +#include "../lib/CAndroidVMHelper.h" #endif #include "../lib/CConfigHandler.h" #include "../lib/CGeneralTextHandler.h" @@ -44,6 +46,10 @@ template class CApplyOnLobby; +#ifdef VCMI_ANDROID +extern std::atomic_bool androidTestServerReadyFlag; +#endif + class CBaseForLobbyApply { public: @@ -151,6 +157,7 @@ void CServerHandler::startLocalServerAndConnect() #ifdef VCMI_ANDROID CAndroidVMHelper envHelper; envHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "startServer", true); + envHelper.Detach(); #else threadRunLocalServer = std::make_shared(&CServerHandler::threadRunServer, this); //runs server executable; #endif diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index 7646f9392..1f4f12b86 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -633,12 +633,12 @@ void CTextInput::notifyAndroidTextInputChanged(std::string & text) auto fun = [&text](JNIEnv * env, jclass cls, jmethodID method) { auto jtext = env->NewStringUTF(text.c_str()); - env->CallStaticObjectMethod(cls, method, jtext); + env->CallStaticVoidMethod(cls, method, jtext); env->DeleteLocalRef(jtext); }; CAndroidVMHelper vmHelper; vmHelper.callCustomMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "notifyTextInputChanged", - "(Ljava/lang/String;)V", fun); + "(Ljava/lang/String;)V", fun, true); } #endif //VCMI_ANDROID diff --git a/lib/CAndroidVMHelper.cpp b/lib/CAndroidVMHelper.cpp index dc0e2b6f9..f4365e1bc 100644 --- a/lib/CAndroidVMHelper.cpp +++ b/lib/CAndroidVMHelper.cpp @@ -42,8 +42,12 @@ CAndroidVMHelper::CAndroidVMHelper() detachInDestructor = false; } } - CAndroidVMHelper::~CAndroidVMHelper() +{ + Detach(); +} + +void CAndroidVMHelper::Detach() { if(envPtr && detachInDestructor) { diff --git a/lib/CAndroidVMHelper.h b/lib/CAndroidVMHelper.h index 48e77d1ae..2c859ddc9 100644 --- a/lib/CAndroidVMHelper.h +++ b/lib/CAndroidVMHelper.h @@ -29,6 +29,8 @@ public: ~CAndroidVMHelper(); + void Detach(); + JNIEnv * get(); jclass findClassloadedClass(const std::string & name); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b5de47afd..1120eccd3 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -168,10 +168,10 @@ set_source_files_properties(${CMAKE_BINARY_DIR}/Version.cpp ) set(lib_HEADERS - ${CMAKE_HOME_DIRECTORY}/include/vstd/CLoggerBase.h - ${CMAKE_HOME_DIRECTORY}/include/vstd/ContainerUtils.h - ${CMAKE_HOME_DIRECTORY}/include/vstd/RNG.h - ${CMAKE_HOME_DIRECTORY}/include/vstd/StringUtils.h + ../include/vstd/CLoggerBase.h + ../include/vstd/ContainerUtils.h + ../include/vstd/RNG.h + ../include/vstd/StringUtils.h StdInc.h ../Global.h diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index fb86032ca..18e7b1c86 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -170,10 +170,17 @@ void CVCMIServer::run() #endif startAsyncAccept(); + +#ifndef VCMI_ANDROID if(shm) { shm->sr->setToReadyAndNotify(port); } +#else + CAndroidVMHelper vmHelper; + vmHelper.callStaticVoidMethod(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS, "onServerReady"); + vmHelper.Detach(); +#endif } while(state == EServerState::LOBBY || state == EServerState::GAMEPLAY_STARTING)