简体   繁体   中英

Android - Compilation error: program type already present

I don't know what is causing this error or what does it mean, but I guess it comes from the gradle file and has something to do with the SDK version.

The full error: Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl

And the gradle:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 19
    buildToolsVersion "27.0.3"

    repositories {
        maven {
            url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
        }
    }

    defaultConfig {
        applicationId "org.eclipse.paho.android.service.sample"
        minSdkVersion 11
        targetSdkVersion 19
    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    implementation 'com.android.support:support-v4:19.0.0'
    implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
    implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.0.2'
}

That is happening because the paho library already have the support v4.

You can also check it by running gradle -q dependencies in the command line to generate a dependency report. You should see where support v4 is coming from.

Finally exclude the library from that specific dependency as such:

dependencies {
implementation 'com.android.support:support-v4:19.0.0'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
      exclude group: 'com.android.support', module:'support-v4'

}

I finally found the solution:

Exclude the module support-v4 in the last dependency, as @Ruan_Lopes said, but don't exclude the group.

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