JavaPhoenixChannels icon indicating copy to clipboard operation
JavaPhoenixChannels copied to clipboard

java.lang.NoClassDefFoundError: org.phoenixframework.channels.Socket$PhoenixWSListener

Open Parsoa opened this issue 8 years ago • 2 comments

I don't if this is really an issue with the library or a mistake on my end so I post here anyway.

This is my build configuration:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.sandzar.paywand"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    productFlavors {
        demo {
            applicationId "com.sandzar.paywand"
            buildConfigField "boolean", "IS_DEMO", "true"
        }
    }
}

repositories {
    mavenCentral()
    maven {
        url 'https://raw.github.com/iainconnor/ObjectCache/master/maven/'
    }
}

def dbflow_version = "4.0.5"
def sqlcipher_version = "3.5.7"

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow-sqlcipher:${dbflow_version}"
    compile "net.zetetic:android-database-sqlcipher:${sqlcipher_version}@aar"

    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'

    compile 'com.fasterxml.jackson.core:jackson-databind:2.8.3'

    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.okhttp3:okhttp:3.8.0'
    compile 'com.google.code.gson:gson:2.8.0'

    compile('com.github.eoinsha:JavaPhoenixChannels:0.2') {
        exclude module: 'groovy-all'
        exclude module: 'okhttp-ws'
        exclude module: 'jackson-databind'
    }
}

I get the following error as soon as any socket methods are invoked:

java.lang.NoClassDefFoundError: org.phoenixframework.channels.Socket$PhoenixWSListener E at org.phoenixframework.channels.Socket.<init>(Socket.java:167) E at org.phoenixframework.channels.Socket.<init>(Socket.java:170) E at com.sandzar.paywand.sockets.SocketService.initiateSocketConnection(SocketService.java:66) E at com.sandzar.paywand.sockets.SocketService.onStartCommand(SocketService.java:50) E at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010) E at android.app.ActivityThread.access$2200(ActivityThread.java:150) E at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442) E at android.os.Handler.dispatchMessage(Handler.java:102) E at android.os.Looper.loop(Looper.java:148) E at android.app.ActivityThread.main(ActivityThread.java:5417) E at java.lang.reflect.Method.invoke(Native Method) E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:764) E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) Process I Sending signal. PID: 4379 SIG: 9

The is the portion of code that causes the error:

private void initiateSocketConnection() {
    try {
        Log.e(DEBUG_TAG, "initiateSocketConnection") ;
        socket = new Socket(Constants.CHANNEL_URL);
        socket.onOpen(new ISocketOpenCallback() {
            @Override
            public void onOpen() {
                try {
                    final ObjectNode payload = objectMapper.createObjectNode();
                    payload.put("token", UserRepository.getInstance().getLoggedInUser().getAuthenticationToken()) ;
                    channel = socket.chan(getUserChannelTopic(), payload);
                    channel.join().receive("ok", new IMessageCallback() {
                        @Override
                        public void onMessage(final Envelope envelope) {
                            Log.e(DEBUG_TAG, "Joined channel successfully") ;
                        }
                    });
                    channel.on("payment:new", new IMessageCallback() {
                        @Override
                        public void onMessage(Envelope envelope) {

                        }
                    }) ;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        socket.onClose(new ISocketCloseCallback() {
            @Override
            public void onClose() {

            }
        });
        socket.onError(new IErrorCallback() {
            @Override
            public void onError(String s) {

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

Here is some extra output from the console:

Java7Support  W  Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added
 art  I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListener>
      I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListener>
      I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListener>
      I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListener>
      I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListener>
      I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListener>
      I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListener>
      I  Rejecting re-init on previously-failed class java.lang.Class<org.phoenixframework.channels.Socket$PhoenixWSListen

Parsoa avatar Jul 20 '17 23:07 Parsoa

This issue appeared because of different versions of okhttp. Retrofit has 3.8.1, but phoenix has 3.6.0 There are two ways to solve this problem right now:

  • Downgrade version of retrofit
  • Fork phoenix and update version of okhttp

makedonsky94 avatar Jul 31 '17 15:07 makedonsky94

Hello i had facing same warning W/Java7Support: Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added

Tried solution --->I have updated java 1.7 to 1.8 in ubuntu os

--->changed java version in app level gradle
compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

and Fork phoenix and update version of okhttp3 from 3.6.0 to 3.10.0

but still getting this warning and i am not able to do socket connection It would be helpful to me if any one had faced same issue and help to solve this issue

Thanks in advance

ND1010 avatar Jan 01 '19 09:01 ND1010