'Failed to create ConnectionFactory object

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'
   .....
}


Solution 1:[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.

Solution 2:[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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KMC
Solution 2 Devenom