The following classes could not be created: android.support.constraint.ConstraintLayout

I have a basic layout with constraint and textview using Android Studio 3 Canary 4 and the newest Gradle 4

SDK: 26

supportLibrary: 26.0.0-beta2

gradle

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

      

layout

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <TextureView
      android:id="@+id/textureView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      tools:layout_editor_absoluteX="190dp"
      tools:layout_editor_absoluteY="232dp"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintHorizontal_bias="0.5"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      />
</android.support.constraint.ConstraintLayout>

      

styles.xml

  <style name="AppThemeWhite" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/white</item>
    <item name="colorPrimaryDark">@color/main_color_500</item>
    <item name="colorAccent">@color/white</item>
    <item name="android:textColorPrimary">@color/main_color_500</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
  </style>

  <style name="AppThemeWhite.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>

  <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

  <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

  <style name="AppTheme.PopupOverlay.white" parent="ThemeOverlay.AppCompat.Light">
    <item name="android:textColor">@color/black</item>
    <item name="colorPrimaryDark">@color/black</item>
    <item name="colorAccent">@color/black</item>
  </style>

  <!-- ToolBar -->
  <style name="ToolBaWhiterStyle" parent="Theme.AppCompat">
    <item name="android:textColorPrimary">@android:color/black</item>
    <item name="android:textColorSecondary">@android:color/black</item>
    <item name="actionMenuTextColor">@android:color/black</item>
  </style>

      

v21 / styles.xml

   <resources>

  <style name="AppThemeWhite" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowContentOverlay">@null</item>
  </style>

  <style name="AppThemeWhite.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
  </style>

</resources>

      

Mistake:

The following classes cannot be instantiated: - android.support.constraint.ConstraintLayout (Open Class, Show Exception, Clear Cache) Tip. Use View.isInEditMode () in custom views to step through code or show sample data when shown in the IDE.

Exception details java.lang.NoSuchFieldError: ConstraintLayout_Layout in android.support.constraint.ConstraintLayout.init (ConstraintLayout.java:440) in android.support.constraint.ConstraintLayout. (ConstraintLayout.java:420) at java.lang.reflect.Constructor.newInstance (Constructor.java:423) at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:733) at android.view.LayoutInflater.inflate (LayoutInflater.inflate. java: 495) to android.view.LayoutInflater.inflate (LayoutInflater.java:397) Copy stack to clipboard

+3


source to share


2 answers


I had the same problem. There is a problem with the support library 26.0.0-beta2

. Going to 26.0.0-beta1

solved the problem.



0


source


I have been trying to get my Android Studio renderer to display ContraintLayout for the last 2 days. Finding solutions was to import various packages, dependencies and update everything.

The solution above did fix the problem.



To rollback go to File -> Project Structure Click Dependencies, remove the AppCompat that is there. Click the + sign and add the library. Find "com.android.support:appcompat-v7:26.0.0-beta1" Resync and rebuild.

-1


source







All Articles