java - 如何将 PAHO/Eclipse MQTT Android 服务带入 Android Studio 项目
问题描述
我根本无法将 PAHO / Eclipse MQTT Android 服务带入 Android Studio 项目。
PAHO 文档建议您将此行添加到 app/build.gradle compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')
但最终我发现它现在已经过时了,那行实际上应该是: api('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')
完整的 app/build.gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.rlasater.mqttsubscriber"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
//implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.0.2'
//This is the problematic line:
api('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')
}
我尝试构建时的结果:
Build failed
:app:compileDebugKotlin
Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class androidx.appcompat.app.AppCompatActivity, unresolved supertypes: androidx.core.app.TaskStackBuilder.SupportParentable
app/src/main/java/com/rlasater/mqttsubscriber/MainActivity.kt
Cannot access 'androidx.core.app.TaskStackBuilder.SupportParentable' which is a supertype of 'com.rlasater.mqttsubscriber.MainActivity'. Check your module classpath for missing or conflicting dependencies
<Previous line repeated several times ...>
Compilation error
需要做什么才能使 Android Studio 项目包含 MQTT Android 客户端?
为什么那条有问题的行会破坏基本的 Android 类 AppCompatActivity?这完全没有意义。
任何建议将不胜感激。我在 PAHO MQTT Java/Kotlin 上找不到比几年前更近的任何文档。我已经能够让更简单的类 (MqttClient) 在 Studio 中工作。显然,让这项服务工作将是最有益的。
解决方案
在 build.gradle 中使用以下依赖项并检查:
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.2'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
推荐阅读
- javascript - document.getElementByClassName 不工作,但 document.getElementById 工作
- django - GeoDjango - LayerMapping:当前事务中发生错误。在“原子”块结束之前,您无法执行查询
- php - 使用动态变量的 PayPal 链式支付
- php - 当用户点击帖子时,为什么变量会在它应该改变之前发生变化?
- powershell - Powershell - 使用文件作为参数创建快捷方式
- angular2-forms - Angular 2 值更改
- linear-programming - AMPL:稀疏语法
- javascript - 如何在本地存储中保存选定的 div 背景颜色?
- json - 当路径中有数字时,如何在 JSON 中获取密钥
- uwp - UWP 后台任务 - 应用程序触发器 - 当文件已存在时无法创建文件