12

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.

4
  • I don't understand why can't you remove either of them? They are essentially the same, only google started to move code to a different place "androidx" and will start adopting that as the sole place for updating the support library (and other componets for that matter). May 10, 2018 at 19:16
  • Remove one of them and adjust the references from your code.
    – Carlos
    May 10, 2018 at 19:19
  • Remove androidx.constraintlayout:constraintlayout:1.1.0 May 10, 2018 at 21:02
  • cant use the editor for constraint layout on android p at present? May 13, 2018 at 17:27

3 Answers 3

31

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.

3
  • 1
    Oh okay. Didn't think it was with the layout. Now i know, Thank you for that. May 11, 2018 at 19:26
  • 8
    Android Studio 3.2 (canary 14) adds the androidx constraint layout when you (from the visual editor) convert a view group into CLayout. Must be a “bug” or something that will go away once androidx. package becomes mainstream and the other is removed. If you were already using CL 1.1.0 (from support), which is what a new project template does for you (includes that in gradle), then you will see this conflict. May 12, 2018 at 18:40
  • I found I was using all the proper matching xmls and ConstraintLayout in my xml file. It was in the build.gradle where I had both of them included as dependencies. Once I removed that, it worked fine. Jul 11, 2018 at 23:16
1

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.

0

I also had the same issue. I was using two different versions for android.arch.core library.So,fixing those versions helped me.Try to use one version throughout your application.Hope it helps someone.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.