TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.54k stars 2.58k forks source link

java.lang.NoClassDefFoundError when changing from 'compile' to 'api' gradle configuration #686

Closed baruchn closed 6 years ago

baruchn commented 6 years ago

Changing compile 'org.java-websocket:Java-WebSocket:1.3.8' to api 'org.java-websocket:Java-WebSocket:1.3.8' causes applications using my library to crush with java.lang.NoClassDefFoundError when trying to instantiate the class which extends WebSocketClient.

As of Gradle 3.0 compile configuration is deprecated and I can't keep using it. According to the documentation api should be it's equivalent in new versions.

Also tried using implementation 'org.java-websocket:Java-WebSocket:1.3.8' but got the same result.

There is a workaround: Adding implementation 'org.java-websocket:Java-WebSocket:1.3.8' in all the application using the library.

Expected Behavior

Open websocket.

Current Behavior

java.lang.NoClassDefFoundError when trying to instantiate the class which extends WebSocketClient.

Possible Solution

Steps to Reproduce (for bugs)

  1. Create an Android library.
  2. Import Java-WebSocket by using api 'org.java-websocket:Java-WebSocket:1.3.8'.
  3. Add a function which opens a new socket to anywhere.
  4. Create Android application which uses the library and import it as a gradle dependency: implementation 'com.your.library'
  5. Use the library to open a socket.

Debug log (for bugs)

Note: me.oriient.ipssdk.ips.WebSocket extends WebSocketClient.

java.lang.NoClassDefFoundError: me.oriient.ipssdk.ips.WebSocket at me.oriient.ipssdk.ips.WebSocketFactory.getSocket(WebSocketFactory.java:32) at me.oriient.ipssdk.ips.SocketWrapper.(SocketWrapper.java:38) at me.oriient.ipssdk.ips.ServerSession.createNewSocket(ServerSession.java:226) at me.oriient.ipssdk.ips.ServerSession.doOpen(ServerSession.java:216) at me.oriient.ipssdk.ips.ServerSession.open(ServerSession.java:212) at me.oriient.ipssdk.ips.CoreLogic.doLogin(CoreLogic.java:264) at me.oriient.ipssdk.ips.CoreLogic.login(CoreLogic.java:255) at me.oriient.ipssdk.ips.Core.login(Core.java:75) at me.oriient.ipssdk.ips.IPSCore.login(IPSCore.java:105) at me.oriient.ipsdemo.activities.LoginActivity.doLogin(LoginActivity.java:130) at me.oriient.ipsdemo.activities.LoginActivity.access$700(LoginActivity.java:36) at me.oriient.ipsdemo.activities.LoginActivity$5.onClick(LoginActivity.java:189) at android.view.View.performClick(View.java:5697) at android.widget.TextView.performClick(TextView.java:10813) at android.view.View$PerformClick.run(View.java:22526) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7224) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Context

## Your Environment
marci4 commented 6 years ago

Hello @baruchn,

thank you for opening this issue and inform me about the changes for gradle.

I think the problem is, that this library was never designed to separate between APIand implementationand therefore I expected that the lib just wokrs with implementation.

Anyway I will take a look into this and maybe work out a better solution!

Greetings marci4

marci4 commented 6 years ago

No real solution found. Compile will still exist.

Closing this issue, exact info will be removed anyway with 1.4.0.