我根本无法将PAHO Eclipse MQTT Android服务带入Android Studio项目中。
PAHO文档建议你在appbuild.gradle编译('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')中添加这行。
但最后我发现现在已经过时了,那行其实应该是:api('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')
完成appbuild.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 JavaKotlin比几年前更近的文档。 我已经能够让更简单的类(MqttClient)在Studio中工作。 显然,让这个Service工作起来将是最有利的。
谢谢你的阅读
在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'