LoginSignup
7
4

More than 3 years have passed since last update.

androidxライブラリの移行で困ったことと対処法

Last updated at Posted at 2019-11-24

問題

AndroidでMQTTを使う場合に重宝するPahoだが、pahoライブラリ使用側をandroidxに移行してもpaho自体はandroidxライブラリを取り込んでいないようでExceptionが吐かれてしまった。
環境は、pahoのandroid.serviceの1.1.1を使っている状態。

implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

吐かれたException。

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager;
at org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:450)

対処法

今回のケースではLocalBroadcastManagerが古いsupport.v4を参照しているため、以下を追加。

gradle.properties
android.enableJetifier=true
android.useAndroidX=true
app/build.gradle
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

もっと汎用的な解決法は、これを追加するでも良いかもしれない(未確認)

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

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

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4