Hi all,
I have run into this strange problem that I would like to understand. I have implemented an Android service that includes native library that it accesses using JNI. The library also calls back to Java code in order to send some intents and get some information.
* the service runs successfully as a user app (on this part) when installed from apk file
* the service runs successfully as a user app (on this part) when build to the image in android build tree
* the service runs successfully as system app, when I just use android:sharedUserId="android.uid.system", sign it with correct key and then install the apk.
* when I use android:sharedUserId="android.uid.system" and build the component as part of the android tree to /system/app folder and the native library installed to /system/lib, calling GetMethodId throws NoSuchMethodError. However to make this more complex, it does not happen with all builds. I have not been able to find out what are the differences and for that I would need some help and ideas.
The C++ code looks like this:
jmethodID callback_=NULL;
jobject obj_=NULL;
void storeCallbackMethodIds(JNIEnv* envP)
{
jclass cls = envP->GetObjectClass(obj_);
if(NULL==cls)
{
LOGE("storeCallbackMethodIds cls(obj_)==NULL");
return;
}
callback_ = envP->GetMethodID(cls, "javaCallback","()Ljava/lang/String;");
if(NULL==callback_)
{
LOGE("storeCallbackMethodIds javaCallback_==NULL");
}
}
JNIEXPORT jint JNICALL Java_com_packet_jni_myMethod
(JNIEnv* envP, jobject obj)
{
obj_= envP->NewGlobalRef(obj);
storeCallbackMethodIds(envP);
...
}
and the exception thrown like this:
E/JavaBinder(19218): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
E/JavaBinder(19218): java.lang.NoSuchMethodError: no method with name='javaCallback' signature='()Ljava/lang/String;' in class Lcom/packet/jni/MyClass;
E/JavaBinder(19218): at com.packet.jni.MyClass.myMethod(Native Method)
E/JavaBinder(19218): at com.packet.service.MyService$MyServiceIfc.myMethod(MyService.java:282)
E/JavaBinder(19218): at com.packet.ifc.MyServiceIfc$Stub.onTransact(MyServiceIfc.java:216)
E/JavaBinder(19218): at android.os.Binder.execTransact(Binder.java:351)
E/JavaBinder(19218): at dalvik.system.NativeStart.run(Native Method)
W/dalvikvm(19218): threadid=8: thread exiting with uncaught exception (group=0x40e8f930)
E/AndroidRuntime(19218): FATAL EXCEPTION: Binder_1
E/JavaBinder(19218): java.lang.NoSuchMethodError: no method with name='javaCallback' signature='()Ljava/lang/String;' in class Lcom/packet/jni/MyClass;
E/JavaBinder(19218): at com.packet.jni.MyClass.myMethod(Native Method)
E/JavaBinder(19218): at com.packet.service.MyService$MyServiceIfc.myMethod(MyService.java:282)
E/JavaBinder(19218): at com.packet.ifc.MyServiceIfc$Stub.onTransact(MyServiceIfc.java:216)
E/JavaBinder(19218): at android.os.Binder.execTransact(Binder.java:351)
E/JavaBinder(19218): at dalvik.system.NativeStart.run(Native Method)
So we can see that the previous calls succeed, correct class (com/packet/jni/MyClass) is found and the method signature is correct, but for some reason the method is not found. The same thing happens to all four C++->Java callbacks I am using, all with different signature. Any ideas what could cause that?
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/0173e14d-39b6-4c05-b101-c94d1f185d90%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
It's been a while since I worked on those and don't have any examples available just now, unfortunately.