bammywells
bammywells

Reputation: 23

android.support.constraint.ConstraintLayout class not found

After importing android native ads templates module from https://github.com/googleads/googleads-mobile-android-native-templates

I cannot run the app because of the following error

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.test.app-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

Upvotes: 2

Views: 16971

Answers (4)

priti
priti

Reputation: 912

Comment these lines if you are getting error in ContentBinding File

        buildFeatures {
           dataBinding true
           viewBinding true
       }

Upvotes: 0

Nidheesh MT
Nidheesh MT

Reputation: 1140

Add dependency for constraint-layout in gradile. See Code

dependencies { //Don't forget to add dependency of constraint-layout implementation 'com.android.support.constraint:constraint-layout:1.1.0' }

Upvotes: 0

Daniel
Daniel

Reputation: 2554

The library you mentioned uses support libraries. Lately all of support packages have been moved to androidx, you can check if your project uses androidx artifacts by checking your build.gradle, there the dependencies should be something like:

implementation 'androidx.appcompat:appcompat:1.0.2'

Androidx and support libraries are not compatible, so if you want to use the library you have 3 choices:

  1. Downgrade you application to use support libraries (not recommended)
  2. Fork the repository and change imports. This is an easy job, you just need to replace all packages from support to androidx.
  3. Import the source code to the android studio and use the option: Refactor |> Migrate to AndroidX (Not sure if it works with modules)

Upvotes: 4

Bryan J. Diaz
Bryan J. Diaz

Reputation: 382

did you notice that the gnt_medium_template_view.xml does not hava a layout?

All the code has to be inside of a Layout like this:

<?xml version="1.0" encoding="utf-8"?>

<ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">
  <com.google.android.gms.ads.formats.UnifiedNativeAdView
      android:layout_height="350dp"
      android:layout_width="match_parent"
      android:id="@+id/native_ad_view"
      android:background="@drawable/gnt_outline_shape"
      >
      <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintBottom_toBottomOf="parent"
          android:layout_centerInParent="true"
          android:padding="5dp"
          android:id="@+id/background"
          >

        <com.google.android.gms.ads.formats.MediaView
            android:id="@+id/media_view"
            android:layout_margin="@dimen/gnt_no_size"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="@dimen/gnt_no_margin"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toTopOf="@id/middle"
            />

    <android.support.constraint.ConstraintLayout
        android:layout_height="60dp"
        android:layout_marginTop="@dimen/gnt_default_margin"
        android:layout_width="match_parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/media_view"
        app:layout_constraintBottom_toTopOf="@+id/body"
        android:id="@+id/middle"
        >
      <android.support.constraint.ConstraintLayout

          android:layout_width="@dimen/gnt_no_size"
          android:layout_height="@dimen/gnt_no_size"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintBottom_toBottomOf="parent"
          android:orientation="horizontal"
          >
        <ImageView
            android:id="@+id/icon"
            android:layout_width="0dp"
            android:layout_weight="0"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/gnt_no_margin"
            android:layout_marginStart="@dimen/gnt_default_margin"
            android:layout_marginBottom="@dimen/gnt_no_margin"
            android:layout_marginEnd="@dimen/gnt_no_margin"
            app:layout_constraintDimensionRatio="H,1:1"
            android:scaleType="fitCenter"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@id/content"
            />
        <android.support.constraint.ConstraintLayout
            android:layout_width="@dimen/gnt_no_size"
            android:layout_height="@dimen/gnt_no_size"
            android:orientation="vertical"
            android:id="@+id/content"
            android:layout_marginLeft="@dimen/gnt_default_margin"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@id/icon"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            >
          <LinearLayout
              android:id="@+id/headline"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="@dimen/gnt_no_size"
              android:layout_weight="0.5"
              app:layout_constraintBottom_toTopOf="@+id/row_two"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toTopOf="parent"
              >

            <TextView
                android:id="@+id/primary"
                android:background="@color/gnt_white"
                android:textStyle="bold"
                android:textSize="@dimen/gnt_text_size_large"
                android:textColor="@color/gnt_gray"
                android:lines="1"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:layout_marginTop="@dimen/gnt_no_margin"
                android:layout_marginBottom="@dimen/gnt_no_margin"
                android:layout_marginStart="@dimen/gnt_no_margin"
                android:layout_marginEnd="@dimen/gnt_no_margin"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                ></TextView>
          </LinearLayout>
          <LinearLayout
              android:id="@+id/row_two"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="@dimen/gnt_no_size"
              android:layout_weight="0.5"
              app:layout_constraintBottom_toBottomOf="parent"
              app:layout_constraintEnd_toEndOf="parent"
              app:layout_constraintStart_toStartOf="parent"
              app:layout_constraintTop_toBottomOf="@id/headline"
              >
            <TextView
                android:background="@drawable/gnt_rounded_corners_shape"
                android:layout_width="@dimen/gnt_ad_indicator_width"
                android:gravity="center"
                android:id="@+id/ad_notification_view"
                android:layout_height="@dimen/gnt_ad_indicator_height"
                android:layout_marginTop="@dimen/gnt_ad_indicator_top_margin"
                android:layout_marginStart="@dimen/gnt_no_margin"
                android:layout_marginEnd="@dimen/gnt_default_margin"
                android:text="Ad"
                android:textColor="@color/gnt_ad_green"
                android:textStyle="bold"
                android:textSize="@dimen/gnt_ad_indicator_text_size"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                >
            </TextView>
            <RatingBar
                android:id="@+id/rating_bar"
                android:background="@color/gnt_white"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textSize="@dimen/gnt_text_size_small"
                android:textColor="@color/gnt_gray"
                android:numStars="0"
                android:lines="1"
                android:layout_marginTop="@dimen/gnt_no_margin"
                android:layout_marginBottom="@dimen/gnt_no_margin"
                android:layout_marginStart="@dimen/gnt_no_margin"
                android:layout_marginEnd="@dimen/gnt_no_margin"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/ad_notification_view"
                app:layout_constraintTop_toTopOf="parent">

            </RatingBar>
            <TextView
                android:id="@+id/secondary"
                android:background="@color/gnt_white"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="top"
                android:textSize="@dimen/gnt_text_size_small"
                android:textColor="@color/gnt_gray"
                android:lines="1"
                android:layout_marginTop="@dimen/gnt_no_margin"
                android:layout_marginBottom="@dimen/gnt_no_margin"
                android:layout_marginStart="@dimen/gnt_no_margin"
                android:layout_marginEnd="@dimen/gnt_no_margin"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/ad_notification_view"
                app:layout_constraintTop_toTopOf="parent"
                ></TextView>

          </LinearLayout>


        </android.support.constraint.ConstraintLayout>


      </android.support.constraint.ConstraintLayout>
      </android.support.constraint.ConstraintLayout>
        <TextView
            android:layout_width="match_parent"
            android:layout_margin="@dimen/gnt_no_size"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/gnt_default_margin"
            android:paddingLeft="@dimen/gnt_default_margin"
            android:id="@+id/body"
            app:layout_constraintBottom_toTopOf="@+id/cta"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/middle"
            android:layout_marginBottom="@dimen/gnt_default_margin"
            />
        <Button
            android:id="@+id/cta"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="@color/gnt_blue"
            android:textColor="@color/gnt_white"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:lines="1"
            android:gravity="center"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/body"
            />

      </android.support.constraint.ConstraintLayout>
  </com.google.android.gms.ads.formats.UnifiedNativeAdView>
</ConstraintLayout>

if you can notice i change merge to ConstraintLayout, you can use others too as: RelativeLayout, LinearLayout, CoordinatorLayout. Of course each one has a different purpose.

I guess it might be the problem, if it is... you need to fix the gnt_small_template_view.xml too. Hope it helps.

Upvotes: 0

Related Questions