Sharath
Sharath

Reputation: 315

Rendering Problems: Android Studio 2.2 - Constraint Layout

I am trying to use Constraint Layout in Android Studio 2.2.

I have installed Android 2.2 studio

I have added the latest Constraint Layout lib in apps gradle and build successfully.

compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'

Now when I try to drag and drop the widgets from the palette to android layout editor, It is not rending to editor and showing the following error.

java.lang.NoClassDefFoundError: android/support/constraint/R$styleable at android.support.constraint.ConstraintLayout$LayoutParams.(ConstraintLayout.java:1180)

Here I am adding the snapshot for the same for better understanding.

what else I am missing here. please help.

Additional Information:

1.Windows 7 OS

2.64 Bit

Build.gradle:

android { compileSdkVersion 23 buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "meterial.example.com.floatingactionbutton"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

enter image description here

Upvotes: 1

Views: 10080

Answers (4)

Dmytro
Dmytro

Reputation: 2309

Let Android Studio do everything for you - actually this is the purpose ConstraintLayout was created for.

So the clear algorithm to import and use ConstraintLayout looks like this.

  1. Create new layout file -> switch to Design tab -> Component tree -> Right button click -> Convert layout to ConstraintLayout -> OK.

enter image description here

  1. Rendering problem error appears in newly converted ConstraintLayout only if it's first ConstraintLayout in your project. In the case Android Studio will ask you to import constraint-layout library. Agree with that.

enter image description here

  1. Here you go - rendering problems warning appears. But if you'll read its suggestions, you'll find the proposition to build the project. Just click build reference in the warning. If warning haven't disappeared, press refresh reference - this might be helpful in 99% cases.

enter image description here

This is the instruction for newly created file. If you try to convert to ConstraintLayout existing file, there are plenty of reasons to warn you about rendering problems. Mostly this happens when you use your own custom widgets, or views from support library, for instance try to wrap something in CardView.

Upvotes: 0

UAK
UAK

Reputation: 19

You'll have to download the repository for constraint before you use it, i got the same error as you have.

So open the Android Studio and Go to Tools > Android > SDK Manager > SDK Tools and expand the Support Repository and click both ConstraintLayout for Android and Solver for ConstraintLayout and apply it'll start downloading.

After that paste the code below to build.gradle(Module:app) file dependencies block. and then go to Tools > Android > Sync Project with Gradle Files, to sync project.

compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'

Click to see where to insert the above line

Refer this page to do entire setup:

Upvotes: 0

Kiran Dsouza
Kiran Dsouza

Reputation: 344

enter image description hereAdd new gradle dependency of constraint-layout

dependencies {
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'  
}

and rebuild the project.

Upvotes: 6

Mithun Sarker
Mithun Sarker

Reputation: 4023

First of all you have no Relative / Linear or any other element in your layout file . As I am seeing in your component tree (bottom left corner) empty . The solution is first add any root element either Relative/Linear layout . Then you can see the the root element in you component tree (bottom left corner) . After right clicking on in you will find a option to convert it to constraint layout . Then a pop up window might appear , check both and click OK then you can use constraint layout . Let me know if it works

enter image description here

Upvotes: 0

Related Questions