Я добавил его, когда делал проект. С тех пор AndroidX Artifact не поддерживает mqt-связь. В чем проблема?

Я добавил его, когда делал проект. С тех пор AndroidX Artifact (checkBox) не поддерживает связь mqt. В чем проблема?

Androidx используется для использования BiometricPrompt.

Ниже мой код mqtt.↓

private lateinit var mqttAndroidClient: MqttAndroidClient
val CLINET_ID: String = MqttClient.generateClientId()

fun connect(applicationContext : Context) {
    val context: Context = applicationContext
    mqttAndroidClient = MqttAndroidClient ( context.applicationContext,"tcp://13.124.231.98:1883", 
CLINET_ID )
    try {
        val token = mqttAndroidClient.connect()
        token.actionCallback = object : IMqttActionListener {
            override fun onSuccess(asyncActionToken: IMqttToken)                        {
                Log.i("Connection", "success ")
                //connectionStatus = true
                // Give your callback on connection established here

 //                    publish("test", "open")

            }
            override fun onFailure(asyncActionToken: IMqttToken, exception: Throwable) {
                //connectionStatus = false
                Log.i("Connection", "failure")
                // Give your callback on connection failure here
                exception.printStackTrace()
            }
        }
    } catch (e: MqttException) {
        // Give your callback on connection failure here
        e.printStackTrace()
    }
}

Ошибки в приведенном выше коде -> val token = mqttAndroidClient.connect()

Моя сборка

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard- 
            rules.pro'
        }
    }
    buildToolsVersion '28.0.3'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.core:core-ktx:1.2.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    //fingerPrint
    implementation 'androidx.biometric:biometric:1.0.0-beta01'
    //mqtt
    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.2'
    implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}

Это проблема версии?

Я попробовал БиометрическийПромпт. в версии, отличной от androidx, чтобы решить эту проблему, но произошла ошибка в коде, который сгенерировал фрагмент и не смог его решить.

Наконец, я подумал, что было бы неплохо запустить mqtt на Androidx, поэтому я пытался несколько раз, но безуспешно.

Если у вас был подобный опыт со мной, и вы решили его, помогите.


person 타터터    schedule 28.11.2019    source источник
comment
Я решил проблему и добавил ее в сборку. указание «androidx.localbroadcastmanager: localbroadcastmanager: 1.0.0»   -  person 타터터    schedule 29.11.2019


Ответы (1)


Вы должны добавить следующие зависимости с androidx

androidx.legacy:legacy-support-v4:1.0.0
androidx.localbroadcastmanager:localbroadcastmanager:1.0.0

Найдите преобразование задачи в GitHub здесь

person Fahry Mohammed    schedule 29.11.2019