问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/59090738/i-added-it-when-i-made-the-project-androidx-artifact-has-not-been-mqt-communica