简体   繁体   中英

How can I bring the PAHO/Eclipse MQTT Android Service into an Android Studio Project

I am simply not able to bring the PAHO / Eclipse MQTT Android Service into an Android Studio project.

The PAHO documentation advises you to add this line to app/build.gradle compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')

But eventually I discovered that is now obsolete, and that line should actually be: api('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2')

Complete app/build.gradle file:

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

Result when I attempt to build:

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

What needs to be done so an Android Studio project can include the MQTT Android Client?

Why does that problematic line disrupt the basic Android class AppCompatActivity? That makes absolutely no sense.

Any suggestions would be most appreciated. I can't find any documentation on the PAHO MQTT Java/Kotlin more recent than some years ago. I have been able to get simpler classes (MqttClient) to work in the Studio. Obviously getting this Service working would be most beneficial.

Use following dependencies in build.gradle and check:

implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.2'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

Documentation is not up to date.

  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
        }

Latest releases You will find here

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM