3

After changing version to Androidx and can not connect to mqtt server. It worked well in other versions than Androidx. Is this a version problem?

My source code and build information is on the link-> I added it when I made the project. AndroidX Artifact has not been mqt communication since then. What is the problem?

My error Logs↓

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.adfdffffaaaaaaa, PID: 28371
java.lang.NoClassDefFoundError: Failed resolution of: 
Landroidx/localbroadcastmanager/content/LocalBroadcastManager;
    at 
org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:450)
    at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:428)
    at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:358)
    at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:313)
    at com.example.adfdffffaaaaaaa.MqttKt.connect(Mqtt.kt:15)
    at com.example.adfdffffaaaaaaa.MainActivity.onCreate(MainActivity.kt:12)
    at android.app.Activity.performCreate(Activity.java:7159)
    at android.app.Activity.performCreate(Activity.java:7150)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3001)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3156)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at 
android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1864)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:205)
    at android.app.ActivityThread.main(ActivityThread.java:6993)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884)
 Caused by: java.lang.ClassNotFoundException: Didn't find class 
"androidx.localbroadcastmanager.content.LocalBroadcastManager" on path: DexPathList[[zip file 
"/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/base.apk", zip file 
"/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_dependencies_apk.apk", zip 
file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_resources_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_0_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_1_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_2_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_3_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_4_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_5_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_6_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_7_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_8_apk.apk", 
zip file "/data/app/com.example.adfdffffaaaaaaa- 
anRxYlYVlgY0rXwazlHcYg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories= 
[/data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/lib/arm64, /system/lib64, 
/system/product/lib64, /system/vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at 
 org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:450) 
    at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:428) 
    at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:358) 
    at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:313) 
    at com.example.adfdffffaaaaaaa.MqttKt.connect(Mqtt.kt:15) 
    at com.example.adfdffffaaaaaaa.MainActivity.onCreate(MainActivity.kt:12) 
    at android.app.Activity.performCreate(Activity.java:7159) 
    at android.app.Activity.performCreate(Activity.java:7150) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3001) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3156) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
    at 
 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1864) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:205) 
    at android.app.ActivityThread.main(ActivityThread.java:6993) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:884) 
    Suppressed: java.io.IOException: No original dex files found for dex location 
 /data/app/com.example.adfdffffaaaaaaa-anRxYlYVlgY0rXwazlHcYg==/split_lib_resources_apk.apk
    at dalvik.system.DexFile.openDexFileNative(Native Method)
    at dalvik.system.DexFile.openDexFile(DexFile.java:354)
    at dalvik.system.DexFile.<init>(DexFile.java:101)
    at dalvik.system.DexFile.<init>(DexFile.java:75)
 E/AndroidRuntime:     at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394)
    at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354)
    at dalvik.system.DexPathList.<init>(DexPathList.java:164)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74)
    at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
    at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
    at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
    at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
    at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
    at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:733)
    at android.app.LoadedApk.getClassLoader(LoadedApk.java:816)
    at android.app.LoadedApk.getResources(LoadedApk.java:1038)
    at android.app.ContextImpl.createAppContext(ContextImpl.java:2391)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6040)
    at android.app.ActivityThread.access$1100(ActivityThread.java:208)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
            ... 6 more
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
타터터
  • 101
  • 2
  • 5
  • 2
    Instead of asking two separate questions for a similar problem. Please edit one question and ask your complete problem in one question. Make sure you ask a [minimal reproducible question](https://stackoverflow.com/help/minimal-reproducible-example). – Hanzla Nov 29 '19 at 09:44
  • 1
    Possible duplicate of [I added it when I made the project. AndroidX Artifact has not been mqt communication since then. What is the problem?](https://stackoverflow.com/questions/59090738/i-added-it-when-i-made-the-project-androidx-artifact-has-not-been-mqt-communica) – Hanzla Nov 29 '19 at 09:45
  • 5
    I solved the problem and added it to the build. an indication 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' – 타터터 Nov 29 '19 at 10:33

2 Answers2

4

Try setting android.enableJetifier=true in gradle.properties file. If that doesn't work, try adding implementation 'androidx.legacy:legacy-support-v4:1.0.0' to build.grade.

This problem has been solved before in the next links, I highly recommend checking them out, specially 420:

https://github.com/eclipse/paho.mqtt.android/issues/321

https://github.com/eclipse/paho.mqtt.android/issues/420

0

I had the same problem. I solved it. my solution:

  1. Add this dependency to the build.gradle(:app)

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

  1. Use these implementations for paho mqtt in the build.gradle(:app)
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
  1. Add these permissions to the manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  1. add this line to gradle.properties
android.enableJetifier=true

It worked for me. I hope works for you too.

Babak Karchini
  • 155
  • 1
  • 8