【问题标题】:Cling Upnp scan causes ClassDefNotFoundError JettyCling Upnp 扫描导致 ClassDefNotFoundError Jetty
【发布时间】:2023-03-22 12:00:01
【问题描述】:

我正在开发一个使用 Cling 执行 UPNP 扫描的 Android 应用。它记录它接收数据包,但随后它因 Jetty 的 NoClassDefFound 异常而崩溃。

下面是我用来执行扫描的代码

ServiceConnection serviceConnection = new ServiceConnection()
    {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service)
        {
            upnpService = (AndroidUpnpService)service;

            upnpService.getRegistry().addListener(listener);
            upnpService.getControlPoint().search();
        }

        @Override
        public void onServiceDisconnected(ComponentName name)
        {
            upnpService = null;
        }
    };

    public HueBridgeSearch(Context context, Activity activity)
    {
        this.context = context;
        this.activity = activity;
    }

    public void startBridgeSearch()
    {
        // Fix the logging integration between java.util.logging and Android internal logging
        org.seamless.util.logging.LoggingUtil.resetRootHandler(
                new FixedAndroidLogHandler()
        );
        Logger.getLogger("org.fourthline.cling").setLevel(Level.ALL);
        listener = new RegistryListener()
        {
            @Override
            public void remoteDeviceDiscoveryStarted(Registry registry, RemoteDevice remoteDevice)
            {
                Log.d(TAG, "Remote Device Discovery Started: " + remoteDevice.getDisplayString());
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void remoteDeviceDiscoveryFailed(Registry registry, RemoteDevice remoteDevice, Exception e)
            {
                Log.d(TAG, "Remote device discovery failed: " + remoteDevice.getDisplayString());
                Log.d(TAG, "Remote device discovery failed: " + e.toString());
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void remoteDeviceAdded(Registry registry, RemoteDevice remoteDevice)
            {
                Log.d(TAG, "Added Found Device: " + remoteDevice.getDisplayString());
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void remoteDeviceUpdated(Registry registry, RemoteDevice remoteDevice)
            {
                Log.d(TAG, "Updated Found Device: " + remoteDevice.getDisplayString());
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void remoteDeviceRemoved(Registry registry, RemoteDevice remoteDevice)
            {
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void localDeviceAdded(Registry registry, LocalDevice localDevice)
            {
                Log.d(TAG, "Local Added Found Device: " + localDevice.getDisplayString());
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void localDeviceRemoved(Registry registry, LocalDevice localDevice)
            {
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void beforeShutdown(Registry registry)
            {
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void afterShutdown()
            {
                Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
            }
        };

        Intent intent = new Intent(activity, AndroidUpnpServiceImpl.class);
        //intent.setClassName("org.fourthline.cling.android", "org.fourthline.cling.android.AndroidUpnpServiceImpl");
        boolean success = context.bindService(intent,
            serviceConnection, Context.BIND_AUTO_CREATE);


    }

以下是我的 gradle 构建文件依赖项

  dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      compile files('libs/cling-core-2.1.0.jar')
      compile files('libs/seamless-util-1.1.1.jar')
      compile 'com.android.support:appcompat-v7:23.3.0'
      compile files('libs/jetty-server-9.2.15.v20160210.jar')
      compile files('libs/jetty-servlet-9.2.15.v20160210.jar')
      compile files('libs/jetty-servlets-9.2.15.v20160210.jar')
      compile files('libs/seamless-http-1.1.1.jar')
  }

编译正常,但运行时出现以下异常

/AndroidRuntime: FATAL EXCEPTION: main                                                                                        Process: com.BoardiesITSolutions.HueRulesAdvanced, PID: 9393
java.lang.NoClassDefFoundError: org.eclipse.jetty.server.Server                                                                                           at org.fourthline.cling.transport.impl.jetty.JettyServletContainer.resetServer(JettyServletContainer.java:165)                                                                                               at org.fourthline.cling.transport.impl.jetty.JettyServletContainer.<init>(JettyServletContainer.java:57) at org.fourthline.cling.transport.impl.jetty.JettyServletContainer.<clinit>(JettyServletContainer.java:55)at org.fourthline.cling.android.AndroidUpnpServiceConfiguration.createStreamServer(AndroidUpnpServiceConfiguration.java:110)
at org.fourthline.cling.transport.RouterImpl.startAddressBasedTransports(RouterImpl.java:427)
at org.fourthline.cling.transport.RouterImpl.enable(RouterImpl.java:132)
at org.fourthline.cling.android.AndroidRouter.enable(AndroidRouter.java:91)
at org.fourthline.cling.UpnpServiceImpl.<init>(UpnpServiceImpl.java:87)
at org.fourthline.cling.android.AndroidUpnpServiceImpl$1.<init>(AndroidUpnpServiceImpl.java:54)
at org.fourthline.cling.android.AndroidUpnpServiceImpl.onCreate(AndroidUpnpServiceImpl.java:54)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
at android.app.ActivityThread.-wrap4(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1427)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)                                                                                              at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

【问题讨论】:

    标签: java android jetty android-cling


    【解决方案1】:

    经过多次反复试验,我终于找到了答案。而不是将 jar 文件下载到 lib 文件夹中并引用 gradle 文件中的 jar 将 build.gradle 更改为:

     dependencies {
          compile fileTree(include: ['*.jar'], dir: 'libs')
          compile files('libs/cling-core-2.1.0.jar')
          compile files('libs/seamless-util-1.1.1.jar')
          compile 'com.android.support:appcompat-v7:23.3.0'
          compile files('libs/jetty-server-9.2.15.v20160210.jar')
          compile files('libs/jetty-servlet-9.2.15.v20160210.jar')
          compile files('libs/jetty-servlets-9.2.15.v20160210.jar')
          compile files('libs/seamless-http-1.1.1.jar')
      }
    

    dependencies {
        compile 'com.android.support:appcompat-v7:23.3.0'
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile files('libs/seamless-util-1.1.1.jar')
        compile files('libs/seamless-http-1.1.1.jar')
        compile files('libs/seamless-xml-1.1.1.jar')
        compile files('libs/cling-core-2.1.0.jar')
        compile 'org.eclipse.jetty:jetty-server:8+'
        compile 'org.eclipse.jetty:jetty-servlet:8+'
        compile 'org.eclipse.jetty:jetty-client:8+'
    }
    

    【讨论】:

      猜你喜欢
      • 2016-02-24
      • 2015-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-27
      • 2012-12-17
      • 2016-10-31
      • 1970-01-01
      相关资源
      最近更新 更多