Android 使用 Jain-SIP 库创建 SipStack 时出错

Android gives error when creating SipStack using Jain-SIP library

在 android studio 中,我的代码一到下一行就失败了。

sipStack = sipFactory.createSipStack(properties);

它给我以下错误。

W/System.err: android.javax.sip.PeerUnavailableException: The Peer SIP Stack: gov.nist.javax.sip.SipStackImpl could not be instantiated. Ensure the Path Name has been set.
...
Caused by: java.lang.NoSuchMethodException: gov.nist.javax.sip.SipStackImpl.<init> [class java.util.Properties]

您知道可能导致此错误的原因吗?


我正在为 Jain-SIP 使用以下依赖项。

compile group: 'javax.sip', name: 'android-jain-sip-ri', version: '1.3.0-91'

代码在IntelliJ中没有问题运行。 我正在使用 Android Studio 和 Ubuntu 18.04.2 LTS。


我的MainActivityclass如下

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Shootist().init();
    }
}

我的射手class如下

public class Shootist implements SipListener {

    public void init() {
        SipFactory sipFactory = SipFactory.getInstance();
        sipFactory.setPathName("gov.nist");
        SipStack sipStack = null;

        String transport = "udp";
        String peerHostPort = "127.0.01:5070";

        Properties properties = new Properties();
        properties.setProperty("android.javax.sip.OUTBOUT_PROXY", peerHostPort + "/" + transport);
        properties.setProperty("android.javax.sip.STACK_NAME", "shootist");
        properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "shootistdebug.txt");
        properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "DEBUG");

        System.out.println("trying to create sip stack");
        // create sip stack
        try {
            sipStack = sipFactory.createSipStack(properties);
            System.out.println("sip stack created");

        } catch (PeerUnavailableException e) {
            e.printStackTrace();
        }



    }

    @Override
    public void processRequest(RequestEvent requestEvent) {

    }

    @Override
    public void processResponse(ResponseEvent responseEvent) {

    }

    @Override
    public void processTimeout(TimeoutEvent timeoutEvent) {

    }

    @Override
    public void processIOException(IOExceptionEvent exceptionEvent) {

    }

    @Override
    public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {

    }

    @Override
    public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {

    }
}

完整的错误输出如下。

07/23 13:55:28: Launching app
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)
I/System.out: trying to create sip stack
W/testapplicatio: Accessing hidden method Lgov/nist/javax/sip/SipStackImpl;-><init>(Ljava/util/Properties;)V (blacklist, reflection, denied)
W/System.err: android.javax.sip.PeerUnavailableException: The Peer SIP Stack: gov.nist.javax.sip.SipStackImpl could not be instantiated. Ensure the Path Name has been set.
        at android.javax.sip.SipFactory.createStack(SipFactory.java:324)
        at android.javax.sip.SipFactory.createSipStack(SipFactory.java:152)
        at com.example.jainsiptestapplication.Shootist$override.init(Shootist.java:35)
        at com.example.jainsiptestapplication.Shootist$override.access$dispatch(Unknown Source:107)
        at com.example.jainsiptestapplication.Shootist.init(Unknown Source:12)
        at com.example.jainsiptestapplication.MainActivity.onCreate(MainActivity.java:13)
        at android.app.Activity.performCreate(Activity.java:7783)
        at android.app.Activity.performCreate(Activity.java:7772)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
        at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5264)
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5172)
        at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:57)
        at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5223)
        at android.app.ActivityThread.access00(ActivityThread.java:220)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2019)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7319)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
    Caused by: java.lang.NoSuchMethodException: gov.nist.javax.sip.SipStackImpl.<init> [class java.util.Properties]
        at java.lang.Class.getConstructor0(Class.java:2332)
        at java.lang.Class.getConstructor(Class.java:1728)
        at android.javax.sip.SipFactory.createStack(SipFactory.java:305)
        ... 25 more
Hot swapped changes, activity restarted
D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)
D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)
I/chatty: uid=10154(com.example.jainsiptestapplication) RenderThread identical 1 line
D/EGL_emulation: eglMakeCurrent: 0xe431a180: ver 2 0 (tinfo 0xe430f220)

主要问题是

sipFactory.setPathName("gov.nist");

应该是

sipFactory.setPathName("android.gov.nist");

初始化与 android 略有不同。或许您可以从这个示例开始 https://github.com/usnistgov/jsip/tree/master/src/examples/android/simplecallsetup 并在此基础上构建。