Android Studio compilation: Program type already present: XXX solution

3Scenario 1: Individual cases

build.gradle

    dependencies {
        classpath ' com.android.tools.build:gradle:3.1.1 ' 
        //
     }

Change to

    dependencies {
          // Currently the latest version [May 15, 2018] 
         classpath ' com.android.tools.build:gradle:3.1.2 ' 
        //
     }

Situation 2: It is indeed a dependency conflict

Error: Program type already present: android.support.v4.app.xxx

Example:
Introduce the following dependency to report the error

    // Paho Android Service 
    implementation ' org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 ' 
    implementation ' org.eclipse.paho:org.eclipse.paho.android.service:1.0.2 '

Excuting an order:

gradlew -q app:dependencies

Checking the dependencies that appeared in support-v4 found that org.eclipse.paho:org.eclipse.paho.android.service:1.0.2
depends on com.google.android:support-v4. Note that it is not com.android.support:support- v4! ! !
pit:

// At first I wrote an exclusion subconsciously, but found it to be useless. . . , The reason is that it uses com.google.android:support-v4 instead of com.android.support 
    implementation( ' org.eclipse.paho:org.eclipse.paho.android.service:1.0.2 ' ){
          exclude group: ' com.android.support ' , module: ' support-v4 ' 
      }

Summary: After
finding the root cause of the dependent problem, eliminate it, and deal with conflicts flexibly according to the prompts!

Exclusion method 1:

configurations {
   all *.exclude group: ' com.google.android ' , module: ' support-v4 ' 
   // Or rough, there will be no pits above all*.exclude module:'support-v4' 
}
dependencies {
...
    implementation ' org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 ' 
    implementation ' org.eclipse.paho:org.eclipse.paho.android.service:1.0.2 '
...
}

Exclusion method 2:

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.google.android ' , module: ' support-v4 ' )
    }

/* Or be rude, there will be no pits above
implementation('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
        exclude module:'support-v4'
    }
    */

Situation 3:

com.android.support: xxx and other official dependency packages v4, v7, v13, etc. The version numbers are consistent, such as 27.1.1

 

Similar Posts: