-
Notifications
You must be signed in to change notification settings - Fork 29
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
Help to use inside XPLPC #188
Comments
It would make sense for your case, sure. Which part are you having trouble with? First make sure you follow the setup for Glancing at your code, the class definition would probably translate as roughly: static constexpr jni::Class kClass {
"com/xplpc/proxy/PlatformProxy",
jni::Static {
jni::Method { "onNativeProxyCallback", jni::Return<void>{}, jni::Params {jstring{}, jstring{} },
}, https://github.com/google/jni-bind#methods I notice some array manipulation which probably looks like: jni::LocalArray<jbyte> some_array { size };
auto* ptr_to_do_some_stuff_with some_array.Pin().ptr(); https://github.com/google/jni-bind#arrays Is there a part specifically I could help with? |
Hi, First, thanks for your time. Im really confused about what i need change and what i need keep. PART 1: The main class between C++ and JNI is this: In this class i have:
PART 2: I have a helper to convert string between platforms:
PART 3: I have a more part that create some objects:
I know that is too much things to answer, but glad if you can help me in these questions. Thanks. |
Part 1:
Part 2:
Part 3:
|
Hi, Im near to finish the migration, but some errors happen when running the tests, but it is compiling the C++ library. I need your help only to understand what im doing wrong with jni-bind and my new/old code. Changes 1: JNIPlatformProxy.hpp
Changes 2: JNIPlatformProxy.cpp
Changes 3: Java_com_xplpc_proxy_PlatformProxy_callNativeProxy
ERROR:
|
Part 1:
You need to have
Without manually inspecting every method, at a glance it does look correct. Part 2:
Otherwise looks fine. Part 3: Your code is crashing when looking up the static method signature. If you try with a non-static method does it work? I just did a quick test with a native => Kotlin static call and it works fine for me. When I double check your signatures, it looks OK. Are you possibly calling this on a secondary thread? If so, just to make sure you have your signatures correct, can you write a super basic app that just calls a static method on the Java class and see if it works? As for strings, I think you may need to use a character array or something similar for now, I'm afraid I don't have special support for string types that aren't supported in C++17 (when I add C++20 I will add it). For now supported types are here. |
Hi, Java VM - Initialize In my
And when initializing on
Static Test If i remove the static from bind the calls StaticRef don't compile. Example:
Changing from:
to:
It works normally in my project using static when i call it manually from my own code:
Ref: https://github.com/xplpc/xplpc/blob/main/jni/lib/src/xplpc/proxy/JNIPlatformProxy.cpp#L75-L81 So, i don't think that the problem is kotlin or java. Strings So, from now i will still use mine functions to convert string and jstring until jni-bind have their functions. |
The function invocation looks right to me. Because I have run it successfully on Kotlin and Java, and there is E2E testing for this (specifically a static that takes a String), I think your JNI Bind init/teardown is possibly wrong. Are you able to make any successful calls? Could you try just replacing the
If that fails (I hope it does), it would confirm you somehow haven't setup your Could you try getting rid of your JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) {
static jni::JvmRef<jni::kDefaultJvm> jvm{pjvm};
return JNI_VERSION_1_6;
} |
Hi, My tests form your last message. Initialize I remove the private variable and use static like you sad:
When run after this, the same error happen.
String test When i call the string test you suggest i get this:
Library initialization My library is initialized inside a |
And the code is changed to this:
|
This happens when This is maybe happening because the With some digging, I've managed to repro a failure where calling a method on a class for the first time from another thread causes failure (I've filed #190). Could you try the following, copy the Sorry for the pain. |
FYI I've created #191 to add unit testing coverage of static strings. Nothing was broken, but it helps further isolate the cause of the issue. |
Hi, I've created a project to test in a more isolated project: It is working. I will add a ContentProvider initializer/load method like i do in XPLPC to understand what is wrong. |
Bah :( I add content provider and it was initialized and work without problems. I don't understand what is the difference :( |
I add the same classes/structure that im using on xplpc project and it works on sample. I don't know why it don't work on xplpc project, since i copy from there. |
I think it's because your Sorry, I'm a bit slammed to try diving into a full sample right now, but, did you manage to grok my last response? I think it possibly gave some context that's helpful Otherwise, just start from the simplest call you can make that fails and build up from there I think is your best bet (like it sounds like you are). |
Hi, Yes, i tried you code:
I migrate to your code, but the same error happen:
Error:
|
Hi, One thing that i discover now is that it is working on XPLPC sample project, but not on tests. Have any different between run a sample android project or run the tests when use this library?
|
On
Button press:
On tests it load the library in the correct sequence, see (1 to 7) but when run the test it will call the number 8 and crash:
The source is:
There is anything special i need do in TEST envrionment? |
Unfortunately it's really hard for me to read code without being able to run it and compile it :( I'm pretty confident that you're seeing the null pointer because your The top reasons I can think of are:
If you can submit a toy example as a pull request to JNI Bind of an existing test I can play with it, but I'm afraid I'm just not setup to build your project. I assume this happens right away in the program? If you want, try setting the JniEnv manually with |
Hi @jwhpryor, The PR is simple: It change few files and only about JNI. To compile you can open it in Android Studio after compile: Step 1:
Step 2:
|
Hello! I think I've resolved as much as I can from this bug. It might be helpful if there's anything outstanding to please file a new bug since this one has gotten pretty large. Per the secondary thread issue, I have a workaround coming shortly (it's actually intended behaviour on Android). |
I’m still with the same problem.
I generate a new header using your bazel task, but the problem persist only
with jni-bind.
Can you give some minutes of your time to help me?
Em sex., 5 de jan. de 2024 às 21:13, Jamieson ***@***.***>
escreveu:
… Closed #188 <#188> as completed.
—
Reply to this email directly, view it on GitHub
<#188 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADAOWBZ5EDNI7BKXZLA33TYNCJKHAVCNFSM6AAAAAA4DX7ZL2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGQYDMMRTHEYTIOI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sorry, are you referring to the crash on the secondary thread? If so, please call I just realised that folks don't have documentation to run off and sadly the Android samples aren't public (and that's where I duplicated that crash). |
FYI I uploaded the Android test that I used to test this fix here. Sadly, I haven't managed to get these tests running under Bazel, but it at least shows the correct flow. |
In my case, i initialize the main class with JVM on JNI_Onload method: https://github.com/xplpc/xplpc/blob/google-jni-bind/jni/lib/src/xplpc/jni/platform.cpp#L26-L29 And it call "initializePlatform" that call jni-bind library: I don't understand what is the problem and why i will need have access to any activity, it don't make sense to me. Can you help me? |
I am sorry for slow response, I am in the middle of many work things 😓 Try calling I agree it seems really stupid your JNI code should have anything to do with your Android is different from Java because it has its own classloader. In regular Java, when a new thread is spawned it shares the same bootloader on other threads, so new classes are found, but on Android, not so. By setting a "fallback loader", native threads have an opportunity to capture a backdoor instance of the application classloader. TBH I think it's kind of idiotic this is the behaviour, but I can only work around what exists, and this was the absolute best I could come up with (I tried really hard). Given the constraints, it's pretty good (but I still hate that you have to do it at all). |
Hi, What need be fixture, any jobject? In my case, the only way to get a valid jobject that don't be released is the old code:
But, if i need back and use the old code only to do it, i think that jni-bind is don't usable to Android (since i need use the old code). Can you help me? |
It just needs to be any |
Hi,
How can i use it inside my project XPLPC:
https://github.com/xplpc/xplpc
Basically is only some functions:
https://github.com/xplpc/xplpc/blob/main/jni/lib/src/xplpc/jni/platform.cpp
and
https://github.com/xplpc/xplpc/blob/main/jni/lib/src/xplpc/jni/support.cpp
Can anyone help me to migrate for JNI Bind?
Make sense in my case?
Thanks.
The text was updated successfully, but these errors were encountered: