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 and, 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: ‘’

android {
compileSdkVersion 27
defaultConfig {
applicationId ""
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner “”
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘

dependencies {
implementation fileTree(include: [’*.jar’], dir: ‘libs’)
implementation '’
implementation '’
testImplementation 'junit:junit:4.12’
androidTestImplementation '’
androidTestImplementation '’
implementation '’
implementation ‘’

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:

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