我在创建项目时添加了它.从那时起,AndroidX Artifact就一直没有进行过通信.问题是什么? [英] I added it when I made the project. AndroidX Artifact has not been mqt communication since then. What is the problem?

查看:292
本文介绍了我在创建项目时添加了它.从那时起,AndroidX Artifact就一直没有进行过通信.问题是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建项目时添加了它.从那时起,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令牌= 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'
}

这是版本问题吗?

我尝试了BiometricPrompt.可以使用androidx以外的版本来解决此问题,但是生成Fragment并无法解决它的代码发生了错误.

最后,我认为在Androidx上运行mqtt会很好,所以我尝试了几次但失败了.

如果您与我有过类似的经历并且已经解决了问题,请帮忙.

解决方案

您应在androidx

中添加以下依赖项

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

在GitHub 此处

I added it when I made the project. AndroidX Artifact(checkBox) has not been mqt communication since then. What is the problem?

Androidx is used to use BiometricPrompt.

Below is my mqtt code.↓

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()
    }
}

Errors in the code above -> val token = mqttAndroidClient.connect()

My Build

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

Is it a version problem?

I tried BiometricPrompt. in the version other than androidx to solve this problem, but an error occurred in the code that generated the Fragment and failed to resolve it.

Finally, I thought it would be good to run mqtt on Androidx, so I tried several times but failed.

If you've had a similar experience with me and you've solved it, help.

解决方案

You should add the following dependencies to with androidx

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

Find the conversion of the issue in GitHub here

这篇关于我在创建项目时添加了它.从那时起,AndroidX Artifact就一直没有进行过通信.问题是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆