将版本更改为Androidx后,它不会变成mqtt connect

o0lyfsai  于 2022-11-03  发布在  Android
关注(0)|答案(2)|浏览(211)

在将版本更改为Androidx后,无法连接到mqtt服务器。它在Androidx以外的其他版本中工作得很好。这是版本问题吗?
我的源代码和构建信息在链接-〉I added it when I made the project. AndroidX Artifact has not been mqt communication since then. What is the problem?
我的错误日志↓

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
xmq68pz9

xmq68pz91#

尝试在gradle.properties文件中设置android.enableJetifier=true。如果不起作用,请尝试将implementation 'androidx.legacy:legacy-support-v4:1.0.0'添加到build.grade
这个问题已经解决了之前在下一个链接,我强烈建议检查他们出来,特别是420:
https://github.com/eclipse/paho.mqtt.android/issues/321
https://github.com/eclipse/paho.mqtt.android/issues/420

hfyxw5xn

hfyxw5xn2#

我也有同样的问题,我解决了它,我的解决方法是:
1.将此依赖项添加到build.gradle(:app)
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
1.在build.gradle(:app)中为paho mqtt使用这些实现

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.将这些权限添加到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.将此行添加到gradle.properties

android.enableJetifier=true

对我有用。我希望对你也有用。

相关问题