Error:Program Type Already Present: Android.Support.Design.Widget.Coordinatorlayout$Behavior

Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior

It worked when I downgrade the support appcompat gradle dependency, like follwing :

implementation 'com.android.support:appcompat-v7:27.0.2'

previously it was

implementation 'com.android.support:appcompat-v7:27.1.0'

OR

Also this can be fixed by just adding support design dependency
of version 27.1.0 or above to your app level build.gradle as following :

implementation 'com.android.support:design:27.1.0'

Error Program type already present: android.support.design.widget.CoordinatorLayout$Behavior

This error comes because you can use older version so simply update your version dependencies.

Change :

compileSdkVersion 26 or targetSdkVersion 26

TO

compileSdkVersion 27 or targetSdkVersion 27

Also Change :

implementation 'com.android.support:appcompat-v7:27.1.1'

implementation 'com.android.support:customtabs:27.1.1'

implementation 'com.android.support:design:27.1.1'

Sync.. and Clean & ReBuild

Program type already present: android.support.compat.R$attr

Hi i have come up with the solution and run successful below gradles with just little version changes:

Main Project Level Gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.30'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.facebook.testing.screenshot:plugin:0.8.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
//Android
minSdkVersion = 24
targetSdkVersion = 28
compileSdkVersion = targetSdkVersion
testInstrumentationRunner = "com.appname.runner.SnapshotTestRunner"
androidSupportLibVersion = "28.0.0"
androidCompatVersion = "1.0.0-beta01"
androidCardViewVersion = "1.0.0"
constraintlayoutVersion = "1.1.3"
okHttpLibVersion = "3.14.0"

//Unit testing
junit = "junit:junit:4.12"
androidTestRunner = "androidx.test:runner:1.1.0-alpha4"
espresso = "androidx.test.espresso:espresso-core:3.1.0-alpha4"
supportTestRules = "com.android.support.test:rules:1.0.2"

//Support Library & UI
constraintLayout = "androidx.constraintlayout:constraintlayout:$constraintlayoutVersion"
supportCompatV7 = "androidx.appcompat:appcompat:$androidCompatVersion"
supportDesign = "com.android.support:design:$androidSupportLibVersion"
supportCardView = "androidx.cardview:cardview:$androidCardViewVersion"
supportCustomTabs = "com.android.support:customtabs:$androidSupportLibVersion"
glide = "com.github.bumptech.glide:glide:3.7.0"

mockito = "org.mockito:mockito-all:1.10.19"
facebookScreenshotTestCommon = "com.facebook.testing.screenshot:layout-hierarchy-common:0.8.0"
facebookScreenshotTestLitho = "com.facebook.testing.screenshot:layout-hierarchy-litho:0.8.0"

// RxJava lib
rxAndroid = "io.reactivex.rxjava2:rxandroid:2.0.1"
rxJava = "io.reactivex.rxjava2:rxjava:2.1.8"
rxJavaRetrofitAdapter = "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"

//Retrofit
retrofit = "com.squareup.retrofit2:retrofit:2.4.0"
okHttp = "com.squareup.okhttp3:okhttp:$okHttpLibVersion"
okHttpLoggingInterceptor = "com.squareup.okhttp3:logging-interceptor:$okHttpLibVersion"
retrofitGsonConverter = "com.squareup.retrofit2:converter-gson:2.3.0"
retrofitScalarsConverter = "com.squareup.retrofit2:converter-scalars:2.3.0"

//Others
parceler = "org.parceler:parceler-api:1.1.9"
parcelerAnnotationProcessor = "org.parceler:parceler:1.1.9"
lombok = "org.projectlombok:lombok:1.16.16"
lombokAnnotationProcessor = "org.projectlombok:lombok:1.16.16"

}

App Level gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.gradletest"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
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(include: ['*.jar'], dir: 'libs')
testImplementation rootProject.ext.junit
androidTestImplementation rootProject.ext.androidTestRunner
androidTestImplementation rootProject.ext.espresso
androidTestImplementation rootProject.ext.supportTestRules
testImplementation rootProject.ext.mockito
testImplementation rootProject.ext.facebookScreenshotTestCommon
implementation rootProject.ext.facebookScreenshotTestLitho
implementation rootProject.ext.constraintLayout
implementation rootProject.ext.supportCompatV7
implementation rootProject.ext.supportDesign
implementation rootProject.ext.supportCardView
implementation rootProject.ext.supportCustomTabs
implementation rootProject.ext.glide
// RxJava lib
implementation rootProject.ext.rxAndroid
implementation rootProject.ext.rxJava
implementation rootProject.ext.rxJavaRetrofitAdapter
//Retrofit
implementation(rootProject.ext.retrofit) {
exclude module: 'okhttp'
}
implementation rootProject.ext.okHttp
implementation rootProject.ext.okHttpLoggingInterceptor
implementation rootProject.ext.retrofitGsonConverter
implementation rootProject.ext.retrofitScalarsConverter
implementation rootProject.ext.parceler
// annotationProcessor rootProject.ext.parcelerAnnotationProcessor
implementation rootProject.ext.lombok
annotationProcessor rootProject.ext.lombokAnnotationProcessor
//Memory leaks
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.multidots:fingerprint-auth:1.0.1'
implementation project(':energyswitchcui')
}

Module("energyswitchcui") gradle:

apply plugin: 'com.android.library'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
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'])

//Unit testing
testImplementation rootProject.ext.junit
androidTestImplementation rootProject.ext.androidTestRunner
androidTestImplementation rootProject.ext.espresso
testImplementation rootProject.ext.mockito
testImplementation rootProject.ext.facebookScreenshotTestCommon
implementation rootProject.ext.facebookScreenshotTestLitho
androidTestImplementation rootProject.ext.supportTestRules

//Support Library & UI
implementation rootProject.ext.constraintLayout
implementation rootProject.ext.supportCompatV7
implementation rootProject.ext.supportDesign
implementation rootProject.ext.supportCardView
implementation rootProject.ext.supportCustomTabs
implementation rootProject.ext.glide
implementation 'com.intuit.sdp:sdp-android:1.0.6'

// RxJava lib
implementation rootProject.ext.rxAndroid
implementation rootProject.ext.rxJava
implementation rootProject.ext.rxJavaRetrofitAdapter

//Retrofit
implementation(rootProject.ext.retrofit) {
exclude module: 'okhttp'
}
implementation rootProject.ext.okHttp
implementation rootProject.ext.okHttpLoggingInterceptor
implementation rootProject.ext.retrofitGsonConverter
implementation rootProject.ext.retrofitScalarsConverter

//Others
implementation rootProject.ext.parceler
// kapt rootProject.ext.parcelerAnnotationProcessor
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

repositories {
mavenCentral()
}

// need for facebook screenshot test in module
apply plugin: 'com.facebook.testing.screenshot'
screenshots {
multipleDevices true
}

Below are the errors that were encountered during gradle and what i have done to solve it:

1) Error: Invoke-customs are only supported starting with Android O (--min-api 26)

Solution: put below lines under android section of app level gradle

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

2) Error: The given artifact contains a string literal with a package reference 'android.support.v4.widget' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.

Solution: Removed "annotationProcessor rootProject.ext.parcelerAnnotationProcessor" from app level gradle and updated this library in main level gradle under "ext" section from 1.1.6 to 1.1.9 'parcelerAnnotationProcessor = "org.parceler:parceler:1.1.9"'
but it does not worked

So i removed that library and successfully build gradle and also can run the project. Here is the dropbox link you can find project on :https://www.dropbox.com/s/ki8gpfdaxh0dzo3/GradleTest.zip?dl=0

3) Above solution will work only in debug mode but in release build we have to also remove this two libraries to build successfully in release build:

facebookScreenshotTestCommon = "com.facebook.testing.screenshot:layout-hierarchy-common:0.9.0"

facebookScreenshotTestLitho = "com.facebook.testing.screenshot:layout-hierarchy-litho:0.9.0"

Program type already present: android.support.design.widget.CoordinatorLayout$Behavior

Update firebase-auth to 15.1.0 and firebase-storage to 15.0.2.
Now they have independent version numbers.

Also update google-services from project .gradle to:

classpath 'com.google.gms:google-services:3.2.1'

Check the release notes here



Related Topics



Leave a reply



Submit