【问题标题】:How can I bring the PAHO/Eclipse MQTT Android Service into an Android Studio Project如何将 PAHO/Eclipse MQTT Android 服务带入 Android Studio 项目
【发布时间】:2020-06-16 00:27:55
【问题描述】:

我根本无法将 PAHO / Eclipse MQTT Android 服务引入 Android Studio 项目。

PAHO 文档建议您将此行添加到 app/build.gradle 编译('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 中工作。显然,让这项服务工作将是最有益的。

【问题讨论】:

    标签: java android build.gradle mqtt paho


    【解决方案1】:

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

    【讨论】:

    • 谢谢;这解决了这个问题。您在哪里找到这些更新的依赖项?
    • @RobertLasater:如果它解决了您的问题,请接受它作为问题的解决方案。
    【解决方案2】:

    文档不是最新的。

      dependencies {
             implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.4'
             implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
             // other dependencies
            }
    

    最新版本您会在这里找到

    https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho.client.mqttv3/

    https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho.android.service/

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 2017-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 2019-01-18
      相关资源
      最近更新 更多