After switching to Constraint Layout, ClassNotFoundException for "android.widget.viewStub"

This happens every time the app starts. I had a similar error at one point earlier in the book and it was apparently due to a mismatch in the app build.gradle between the version of com.android.support:appcompat-v7 and com.android.support:recyclerview-v7, but they are the same now (26.0.0).

2 suggestions:

  1. Make sure you’re on the latest version of Android Studio. That normally helps a lot with strange issues with the tools.
  2. Verify that your build.gradle file is set up correctly. The version of the support libraries that you use should match the compileSdkVersion in your build.gradle file. So, your compileSdkVersion should be 26 to match your libraries. Feel free to post your build.gradle here so I can check it out.

I downloaded Android Studio last week when I started working through the book: build.gradle (I have also tried it with version 26 everywhere instead of 27) is below.

It’s not a huge deal, I just switched back to a LinearLayout and continued on with the project:

apply plugin: ‘com.android.application’

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.bignerdranch.android.criminalintent"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro
}
}
}

dependencies {
implementation fileTree(include: [’*.jar’], dir: ‘libs’)
implementation 'com.android.support:appcompat-v7:27.0.0’
implementation 'com.android.support.constraint:constraint-layout:1.0.2’
testImplementation 'junit:junit:4.12’
androidTestImplementation 'com.android.support.test:runner:1.0.1’
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1’
implementation 'com.android.support:support-v4:27.0.0’
implementation ‘com.android.support:recyclerview-v7:27.0.0’
}

Yea, I’m not sure what the issue is. The tools are constantly changing and sometimes things break. There are a few things that you can play around with to help the issue.

I’m glad you were able to move forward with LinearLayout.

Figure 9.5 Converting the root. It says to right click the root LinearLayout and select convert to constraint layout in the book. But when I right click I don’t get the same list of choices. Where the figure 9.5 shows convert to constraintLayout mines say “Compare with…”

I had the same issue with recyclerview as well it took me quite a while to find the solution.

I found my solution by switching to design view.

This Android Developers link gave me the solution for my problem:
https://developer.android.com/training/constraint-layout/index.html

Convert a layout

Figure 3. The menu to convert a layout to ConstraintLayout
To convert an existing layout to a constraint layout, follow these steps:
Open your layout in Android Studio and click the Design tab at the bottom of the editor window.
In the Component Tree window, right-click the layout and click Convert layout to ConstraintLayout