34

I've been trying this all evening to no avail so I'm going to list my exact steps starting from scratch.

  • I've installed the support package via SDK manager.
  • I create a new android project which I call "testinggridlayout".
  • The build target I select is Android 2.1 API 7.
  • List item

This will be my project which I want to be able to create a grid layout on.


To set up the support package these are my steps:

  • Right-click the project I've just created and select - New - Android Project
  • Name it GridLayout and select create project from existing source and browse to:

android-sdks\extras\android\support\v7\gridlayout

  • Right-click my testinggridlayout project and click properties:
  • under Java Build Path - select the Projects tab, then Add.
  • select my project "GridLayout" and click OK, then Ok.

At this point

If I go into the main.xml layout manually insert this code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<GridLayout
    android:background="#FFFFFF"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:columnCount="8"
    android:rowCount="5" >

</GridLayout>

</LinearLayout>

I get the error:

The following classes could not be found: - GridLayout (fix build path, edit XML).

If I change

<GridLayout> & </GridLayout>
to
<android.support.v7.widget.GridLayout> & </android.support.v7.widget.Gridlayout>

I receive the same error:

The following classes could not be found: - android.support.v7.widget.GridLayout (fix build path, edit XML).

At that point I created a folder in my project called "libs".

I then copied the android-support-v7-GridLayout.jar file under libs in the GridLayout project to this folder.

I right clicked this file in my "libs" folder in "testinggridlayout" and selected "Add to Build Path".

My error then changed to:

The following classes could not be instantiated: - android.support.v7.widget.GridLayout (open class, show error log)

Which bit(s) have I missed out/ shouldn't have done?

halfer
  • 19,824
  • 17
  • 99
  • 186
Kyohei Kaneko
  • 932
  • 2
  • 8
  • 25

7 Answers7

15

I use intellij idea, so it's not exactly your case, but maybe it will be helpfull. I struggled with setting this up whole day, then it suddenly worked. I'll describe my setup so you can compare:

  1. setup the GridLayout project as library project. Example of setting up can be found at android developer site here
  2. setup your main project as usual, reference the library project as described in the link above.
  3. add libraries to your main project. I used latest android-support-v13.jar and android-support-v7-gridlayout.jar. NOTE: I used the v7 support library in the main project, not the library project. In fact, checking it now - in library project I don't reference the v7 support.
  4. Use full package name in the layout file: <android.support.v7.widget.GridLayout /> instead of <GridLayout />
  5. use custom namespace, something like this: xmlns:grid="http://schemas.android.com/apk/res-auto" in your layout file to use custom attributes defined in the library project in your tag, like grid:columnCount

hope this helps. I'm currently trying it, not even sure it is something I need :)

khusrav
  • 5,267
  • 5
  • 27
  • 38
  • 1
    In my case eclipse asked to install the support package, but still didn't recognize it. For me just using Android.support.v7.widget.GidLayout fixed it. Thanks! – Niels Nov 03 '12 at 23:24
10

If someone is having same problem here's a solution that worked for me:

After importing project into a workspace you need to add it as a dependency using Android tab and not Java Build Path

Project -> Properties -> Android -> Library -> [Add...]

I also ticked Is Library.

Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69
Mahakala
  • 761
  • 1
  • 10
  • 16
5

Copy android-support-v7-gridlayout.jar from the folder Android_SDK_folder\extras\android\support\v7\gridlayout\libs. Then, paste it in your project MyAndroidProject\libs folder.

Sridhar Nalam
  • 527
  • 8
  • 9
4

The support-v7-gridlayout.jar revision 7 had some issues. Now it was updated to revision 8, see compatibility-library just update it and its gonna work. Dont forget to change the support package for all of your library and dependencies or you gotcha an error of mismatch.

Lasse Samson
  • 1,752
  • 3
  • 18
  • 17
Marckaraujo
  • 7,422
  • 11
  • 59
  • 97
2

Edit you project's (and library project's too) .classpath file like this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>
Lingviston
  • 5,479
  • 5
  • 35
  • 67
  • Adding the exported="true" attribute to the com.android.ide.eclipse.adt.ANDROID_FRAMEWORK classpathentry in both the main project and the android-support-v7-gridlayout project, then restarting Eclipse worked for me. – Andrew Porritt Oct 31 '13 at 17:33
1

In addition to the suggestions listed above I had to do one more thing before I could preview the grid layout in Eclipse:

  1. Right-click the project android-support-v7-gridlayout.
  2. Go to Properties > Java Build Path > Libraries
  3. Add libs/android-support-v7-gridlayout.jar to the Libraries.
  4. Go to Order and Export and check the jar added in the previous step.

Hope it helps!

argenkiwi
  • 2,134
  • 1
  • 23
  • 26
0

To make 7v Samples (/extras/android/support/samples/Support7Demos/) to work, do the following:

  1. Import all projects from here /extras/android/support/v7
  2. Create /libs directory for Support7Demos project
  3. Put all *.jar files in /libs directory of these projects and add them to Support7Demos/libs
Henadzi Rabkin
  • 6,834
  • 3
  • 32
  • 39