Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program type already present: android.support.constraint.BuildConfig

build.gradle (Module: app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    buildToolsVersion '27.0.3'
    defaultConfig {
        multiDexEnabled true
        applicationId "tk.megh.myapplication"
        minSdkVersion 'P'
        targetSdkVersion 'P'
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        preDexLibraries = false
    }
}



dependencies {
    implementation 'com.android.support:multidex:1.0.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:+'
    testImplementation 'junit:junit:4.12'

}

Well i think i know what's causing the error, if you look at the dependencies there are two redundant packages with different names

com.android.support.constraint:constraint-layout:1.1.0 androidx.constraintlayout:constraintlayout:1.1.0

But i can't remove either of them because they are used by some packages. I'm a novice in android development, so i don't have much idea about any workarounds.

if i remove

implementation 'com.android.support.constraint:constraint-layout:1.1.0'

i get this error while debugging:

    java.lang.RuntimeException: Unable to start activity 
ComponentInfo{tk.megh.myapplication/tk.megh.myapplication.MainActivity}: 
android.view.InflateException: Binary XML file line #2: Binary XML file 
line #2: Error inflating class android.support.constraint.ConstraintLayout

and if i remove

implementation 'androidx.constraintlayout:constraintlayout:1.1.0'

i get the following error while debugging:

 java.lang.RuntimeException: Unable to start activity 
ComponentInfo{tk.megh.myapplication/tk.megh.myapplication.DisplayMessageActivity}: 
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: 
Error inflating class androidx.constraintlayout.widget.ConstraintLayout

Additional Details:

imports of MainActivity.java:

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

imports of DisplayMessageActivity.java:

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;   

Thanks in advance.

like image 803
Meghashyam Bhandary Avatar asked May 10 '18 19:05

Meghashyam Bhandary


2 Answers

The errors indicate that you're using the ConstraintLayout in your layout xml files.

Keep only one version of the library and make sure, that you are using that version's ConstraintLayout in your xmls.

So, if you keep androidx, check your layout files and make sure, you are using androidx.constraintlayout.ConstraintLayout there, and not android.support.constraint.ConstraintLayout.

like image 147
Ridcully Avatar answered Nov 14 '22 17:11

Ridcully


Be careful not to reference com.android.support.constraint:constraint-layout and androidx.constraintlayout:constraintlayout at the same time. Settle on one (preferably androidx), remove the other, and make sure the package names are consistent in your layout files too. That fixed the issue for me.

like image 1
Baptiste Candellier Avatar answered Nov 14 '22 18:11

Baptiste Candellier