PJSip account registration

I am trying to add PJSip to a project that I am working on. I have this method for registering my account, but every time a "Fatal signal 11" error occurs.

Here is the method

public int setRegistration() { int status = pjsuaConstants.PJ_FALSE; /* Register to SIP server by creating SIP account. */ int[] accId = new int[1]; accId[0] = 1; String uName = getUserName(); String passwd = getPassword(); String server = getSIPServer(); pjsua_acc_config acc_cfg = new pjsua_acc_config(); pjsua.acc_config_default(acc_cfg); acc_cfg.setId(pjsua.pj_str_copy("sip:" + uName + "@" + server)); acc_cfg.setReg_uri(pjsua.pj_str_copy("sip:" + server)); acc_cfg.setCred_count(1); acc_cfg.getCred_info().setRealm(pjsua.pj_str_copy(server)); acc_cfg.getCred_info().setScheme(pjsua.pj_str_copy("digest")); acc_cfg.getCred_info().setUsername(pjsua.pj_str_copy(uName)); acc_cfg.getCred_info().setData_type(pjsip_cred_data_type.PJSIP_CRED_DATA_PLAIN_PASSWD.swigValue()); acc_cfg.getCred_info().setData(pjsua.pj_str_copy(passwd)); Log.d("status", "acc is adding.."); status = pjsua.acc_add(acc_cfg, pjsuaConstants.PJ_TRUE, accId); Log.d("status", "acc is added"); if (status == pjsuaConstants.PJ_SUCCESS) { status = pjsua.acc_set_online_status(accId[0], 1); Log.d("acc_set_online_status returned stauts=", String.valueOf(status)); } else { Log.d("Error status=", String.valueOf(status)); } return status; } 

I get an error in the line status = pjsua.acc_add(acc_cfg, pjsuaConstants.PJ_TRUE, accId); . I know that the username, server and password are not null. I have considered several issues regarding this and am not using it.

How can I register my account?

thanks

***** EDIT ****** After tracking this through blogs and forums, I got this error, but got another. The reason for this error was because pjsua_init never successful. It was successful because it gave me this error

 11-04 10:19:20.973: E/AndroidRuntime(2961): FATAL EXCEPTION: main 11-04 10:19:20.973: E/AndroidRuntime(2961): java.lang.UnsatisfiedLinkError: Native method not found: org.pjsip.pjsua.pjsuaJNI.init:(JLorg/pjsip/pjsua/pjsua_config;JLorg/pjsip/pjsua/pjsua_logging_config;JLorg/pjsip/pjsua/pjsua_media_config;)I 11-04 10:19:20.973: E/AndroidRuntime(2961): at org.pjsip.pjsua.pjsuaJNI.init(Native Method) 11-04 10:19:20.973: E/AndroidRuntime(2961): at org.pjsip.pjsua.pjsua.init(pjsua.java:812) 

I also received this warning

 No implementation found for native Lorg/pjsip/pjsua/pjsuaJNI;.init (JLorg/pjsip/pjsua/pjsua_config;JLorg/pjsip/pjsua/pjsua_logging_config;JLorg/pjsip/pjsua/pjsua_media_config;)I 

Why is this not a native method? I look through the libraries that I named, but apart from that I don’t know why this is not working.

Any help on this would be great. Thanks

PJ Code

pjsua.java

 public synchronized static int init(pjsua_config ua_cfg, pjsua_logging_config log_cfg, pjsua_media_config media_cfg) { return pjsuaJNI.init(pjsua_config.getCPtr(ua_cfg), ua_cfg, pjsua_logging_config.getCPtr(log_cfg), log_cfg, pjsua_media_config.getCPtr(media_cfg), media_cfg); } 

pjsuaJNI.java

 public final static native int init(long jarg1, pjsua_config jarg1_, long jarg2, pjsua_logging_config jarg2_, long jarg3, pjsua_media_config jarg3_); 

pjsua_wrap.cpp

 SWIGEXPORT jint JNICALL Java_org_pjsip_pjsua_pjsuaJNI_init(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_, jlong jarg3, jobject jarg3_) { jint jresult = 0 ; pjsua_config *arg1 = (pjsua_config *) 0 ; pjsua_logging_config *arg2 = (pjsua_logging_config *) 0 ; pjsua_media_config *arg3 = (pjsua_media_config *) 0 ; pj_status_t result; (void)jenv; (void)jcls; (void)jarg1_; (void)jarg2_; (void)jarg3_; arg1 = *(pjsua_config **)&jarg1; arg2 = *(pjsua_logging_config **)&jarg2; arg3 = *(pjsua_media_config **)&jarg3; result = (pj_status_t)pjsua_init((pjsua_config const *)arg1,(pjsua_logging_config const *)arg2,(pjsua_media_config const *)arg3); jresult = (jint)result; return jresult; } {"init", "(JLorg/pjsip/pjsua/pjsua_config;JLorg/pjsip/pjsua/pjsua_logging_config;JLorg/pjsip/pjsua/pjsua_media_config;)I", (void*)& Java_org_pjsip_pjsua_pjsuaJNI_init}, 

EDIT 2

So, after working on this, I came to disappointment. I don’t see what I'm doing wrong, so I will put my whole process here to find out if anyone has a suggestion.

  • I start by getting the pjsip library: svn co http://svn.pjsip.org/repos/pjproject/trunk pjproject
  • run `./configure --prefix = / usr / local
  • make dep and make
  • sudo make install

  • Then I get the code pjjni svn checkout svn://svn.code.sf.net/p/pjsip-jni/code/ pjsip-jni-code

  • I follow the makefile instructions
  • After executing the Makefile (after some code cleaning) I have 2 .so files (libpjsua_jni.so and libpjsua_jni_x64.so)
  • Create jni folder with Android.mk and .so files
  • Run ndk-build ( How to load another .so file into an Android project? )
  • Add to ADT
  • Close the project. Change your native support from Java to Android. Open project ( Convert existing project to Android project in Eclipse? )
  • Add this project to the TestPJ project ( Android -> Library -> Add )
  • Call System.loadLibrary("pjsualib") - The name of the new lib.so
  • Error receiving

    11-22 13: 55: 44.784: W / dalvikvm (11464): implementation not found for native Lorg / pjsip / pjsua / pjsuaJNI; .swig_module_init :() V 11-22 13: 55: 48.792: W / dalvikvm (11464) : Ljava / lang / UnsatisfiedLinkError exception; throws when initializing Lorg / pjsip / pjsua / pjsuaJNI; 11-22 13: 55: 51.417: E / AndroidRuntime (11464): java.lang.UnsatisfiedLinkError: native method not found: org.pjsip.pjsua.pjsuaJNI.swig_module_init :() V 11-22 13: 55: 51.417: E / AndroidRuntime (11464): at org.pjsip.pjsua.pjsuaJNI.swig_module_init (native method) 11-22 13: 55: 51.417: E / AndroidRuntime (11464): at org.pjsip.pjsua.pjsuaJNI. (PjsuaJNI.java:1450)

Any help would be great. Thanks!

+6
source share
2 answers

An example project that explores JNI calls with Java and C can be found here .
The error mentioned in the question (java.lang.UnsatisfiedLinkError: native method not found: org.pjsip.pjsua.pjsuaJNI) means one of the following problems:

- incorrect name of the native method or / and its arguments / return value. If you have access to your own library code, you can fix it. According to the error message and JNI considerations, the native method should be named Java_org_pjsip_pjsua_pjsuaJNI_init (JNIEnv * env, jobject obj, ..), where env is a pointer to the JVM interface, obj is a pointer to "this", and the rest of the arguments can be determined from java The init method of the pjsuaJNI class of the org.pjsip.pjsua package. Simple parameter types should be jint, jstring, etc. The return value must also be correct. Fixing all this allows you to use this method from the pjsuaJNI class. For more information, see the Oracle documentation for Oracle Documentation for Java 6 JNI (or Java 7 if you are using Android 4.4).

- invalid java method name / signature / class name or package name . This case is almost turned to the first. Again, according to the specified error name, the method should be "init", the class name pjsuaJNI and the package org.pjsip.pjsua. If at least one of them is erroneous, the indicated exception will occur. Signature or parameters must also be correct. Within the boundaries of this error, it can be considered as method parameters (in addition, the task appears in the native JNIEnv *). Therefore, it is also necessary to check and eliminate if necessary.
In the case of a call from the native code to the java signature, it can be considered as a representation of the java method with parameters as a string and it can be viewed using the javap -s * .class command applied to the java * .class file. And in the last warning from the question, you can see this method signature.

Also, to use the method, the pjsip library must have System.loadLibrary () loaded in some static section of the Java class.

Unfortunately, this problem occurs at runtime (it would be nice if it happened at compile time).

+3
source

A little late, but I will try to help with this. I think your problem should be related to your native method, which was not surrounded by extern "C"{} and the name mangling in C ++.

If you do not declare one native C-function as extern "C" , the C ++ assembly manages it, and the JNI mechanism cannot find the built-in method that matches the provided signature. On the other hand, declaring it as an external C function, the creator creates both modified and immutable versions, and JNI can find the correct one.

Hope this helps.

0
source

Source: https://habr.com/ru/post/955711/


All Articles