-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JNI_OnLoad/JNI_OnUnload - default implementation not optional #50
Comments
I think you are right, the idea was to provide just an header, and let you include the header if you need a pre-written JNI_OnLoad And everything was fine until this change , https://github.com/cross-language-cpp/djinni-support-lib/pull/26/files @jothepro , do you remember if there was a reason to add that file I fear I can not recall all details we discused back then ... |
I recall that the following was my thought-process leading to these changes: There is 2 ways how you can use the djinni-support-lib in your project: As static or as shared lib. If you use the support-lib as shared library, it has to provide it's own JNI initialization mechanism for it to be loaded properly, which is provided by If you choose to provide your own implementations of That's how it is still possible to choose a custom loading implementation in your library. Only in case you use the support-lib as shared library, the loading of the support-lib itself always depends on the default implementation, while the library depending on the support-lib can choose it's own loader. I struggle to describe the whole situation in short words, that's why I tried to visualize it in the PR: cross-language-cpp/djinni-generator#49 (comment) The main flaw of this concept may be that it's difficult to grasp. If you have an idea on how this could be made clearer in the docs or the sources, I'd be super grateful! If there is something that's not clear to you after reading this answer and the linked thread, pls keep asking! BTW I am not sure if I ever tested using the support-lib as shared library. @a4z pointed out here that this may be an edge case that's not common. |
Thanks @jothepro , I think you described the situation very well. I think we can ask CMake if it is generating a dynamic library, and if than do that djinni-support-lib/CMakeLists.txt Line 24 in 42c05ca
otherwise, do nothing. So if we need to query DJINNI_LIBRARY_TYPE and if not set cmakes DJINNI_LIBRARY_TYPE, and add the file only if we build a dynamic library |
All you need to do is add the support lib into the android package and load 2 shared libs instead of only 1, so technically we should not close the door but we maybe need better docs .... |
This should fix cross-language-cpp#50, If users do not define their own functions, the generator will generate a file that needs to be inlcuded. For an own JNI_OnLoad/JNI_OnUnload function, the generator needs to be informed. If the support lib is used as a dynamic lib, the JNI functions are not optional.
Thanks for the follow-up. We were using a custom |
Fix #50, remove jinni_jni_main.cpp from the static library. Even if this change will not change anything for the end user, it makes the intention of the djinni_jni_main.cpp file more explicit.
This is an interesting use case, especially since I would expect that the unload of the library happens when the program exits, what should be at at point in time async operations are done. Anyhow, we removed the file from the static lib to make the indention of the djinni_main in the support lib more clear. |
In
djinni_jni_main.hpp
it is written:Unfortunately the djinni-support-lib has not made the inclusion of this default implementation optional.
The text was updated successfully, but these errors were encountered: