0

Is it possible to make a callback to a private java method from C++ over JNI? The following piece of code that works if PrivateMethodName is public does not work if it's private

jobject jobjectRef = env->NewGlobalRef(jobject javaObject);
jclass jobjectClass = env->GetObjectClass(jobjectRef );
jmethodID callbackId = env->GetMethodID(configServiceClass, "PrivateMethodName", "()Ljava/lang/String;");
env->CallObjectMethod(jobjectRef , callbackId )

Edited:

My javaObject belongs to a concrete implementation of an abstract class and the abstract class actually has the private method.I think that's the issue.

I get

2020-07-27 19:12:46.486 2285-2285/com.test.application A/art: art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.NoSuchMethodError: no non-static method "Lcom/test/application/ConcreteClass;.PrivateMethodName()Ljava/lang/String;"
Botje
  • 26,269
  • 3
  • 31
  • 41
rstr1112
  • 308
  • 4
  • 13
  • What do you mean by "does not work"? Also, [see this](https://stackoverflow.com/questions/12208387/can-a-native-method-call-a-private-method) – PaulMcKenzie Jul 28 '20 at 01:39
  • @PaulMcKenzie Updated – rstr1112 Jul 28 '20 at 02:18
  • We have no way of telling whether your native code is correct since we haven't seen the Java code. It even contains what appears to by a syntactic error (`jobject javaObject`). You should post a minimal complete example. – Michael Jul 28 '20 at 07:12
  • I just noticed you tagged your application as "android". Is it possibly ProGuard is renaming the method behind your back? Try adding the class/method to the ProGuard "keep" list. – Botje Jul 28 '20 at 10:22
  • JNI does not enforce any private or final modifiers. Have you tried to see what the correct signature of the method in question is by using `javap' on the .class file? – TainToTain Aug 03 '20 at 18:16

0 Answers0