Search code examples
androidclassnotfoundexceptionandroid-gridlayout

"ClassNotFoundException: android.support.v7.widget.GridLayout" even if it is actually imported


I have quite an odd problem. I'm using Android Studio 2.1 on Ubuntu 15.10.

I'm trying to implement the GridLayout from v7 support libraries. I installed the Android Support Library and Android Support Repository from the SDK Manager and added the gridlayout to my apps build.gradle dependencies:

compile 'com.android.support:design:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:gridlayout-v7:23.3.0'

When adding it to my layouts XML file it autocompletes correctly just as if it is imported like it should.

<android.support.v7.widget.GridLayout xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:columnCount="4"
            app:rowCount="4"
            android:id="@+id/keypadButtons"
            app:alignmentMode="alignBounds">
...

But when I went to build the project to see what it looks like on a device, it for some reason fails.

When I wanted to check it out on the Design view, I see that I have a parse error in my event log which states:

java.lang.RuntimeException: java.lang.ClassNotFoundException: android.support.v7.widget.GridLayout

Edit: When also viewing the GridLayout in Design view, it even renders it as it should (in my case 4 columns and 4 rows). But gives the parse error of the GridLayout class not found and fails to show my Component Tree of other elements.

Have I missed some step when adding the library? I've used other v4 and v7 support libraries on Windows without any issues. Could it be Linux permission issues?


Solution

  • The solution to the build problem was as simple (and somewhat embarrasing) as doing a project clean under Build -> Clean Project. That solved my issue regarding the app not building.

    Now I was also stuck with the GridLayout class not being found in Design view. The solution for it I found was to invalidate the caches under File -> Invalidate Caches / Restart (Note: This will clear your local history in Android Studio). And after a restart the GridLayout class was found correctly.