Reputation: 315
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'
}
}
}
Upvotes: 1
Views: 10080
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.
ConstraintLayout
-> OK.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.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
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
Reputation: 344
Add new gradle dependency of constraint-layout
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
}
and rebuild the project.
Upvotes: 6
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
Upvotes: 0