Failed to create ConnectionFactory object

妖精的绣舞 提交于 2021-02-10 10:52:09

问题


I'm building an android chat app using rabbitmq and the project builds without any issue. However, I'm having an issue in creating ConnectionFactory object. It gives me the following error

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.zabu.kyimoecho.mosaic, PID: 9002
    java.lang.NoClassDefFoundError: com.rabbitmq.client.impl.nio.-$$Lambda$NioParams$NrSUEb8m8wLfH2ztzTBNKyBN8fA
        at com.rabbitmq.client.impl.nio.NioParams.<clinit>(NioParams.java:37)
        at com.rabbitmq.client.ConnectionFactory.<init>(ConnectionFactory.java:153)
        at com.zabu.kyimoecho.mosaic.GenericIdentity.<init>(GenericIdentity.kt:11)
        at com.zabu.kyimoecho.mosaic.Admin.<init>(Admin.kt:9)
        at com.zabu.kyimoecho.mosaic.MainActivity.<init>(MainActivity.kt:10)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        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)

I've looked online and the suggestions I came across didn't resolve this issue.

I'm using Android 3.3.2, JDK 8 and Rabbitmq 5.6.0.

build.gradle :

....
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
...
dependencies {
   implementation 'com.rabbitmq:amqp-client:5.6.0'
   .....
}

回答1:


Just for the sake of reference (if anybody runs into similar issue), I resolved this issue by changing targetSdkVersion to 27 from 24 in build.gradle.




回答2:


I've faced this same issue. If you see the documentation on this page RabbitMQ Documentation, it says that amqp-client:5.x series library is meant for Android 7 (Nougat) and above. If you are using any Android version below Android 7 then you can use the amqp-client:4.x series library.

I wanted to use both so I got one of the amqp-client:4.x series library source code and recompiled it with a slightly different package name and use the jar file so that I could use both the updated 5.x series for newer Android versions and 4.x series for lower Android versions.



来源:https://stackoverflow.com/questions/55201745/failed-to-create-connectionfactory-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!