1

An app has been using android.support.v7.widget.GridLayout for a while without any problem. I upgraded Android SDK Tools to 22.0.1 this morning. Now, it seems that the app cannot see the library anymore. The Java code has the following error:

The import android.support.v7.widget cannot be resolved

I tried to add a GridLayout to a dummy layout file by dropping GridLayou to it thinking this would help configure the project properly for using GridLayout. However, this generates the following error:

The following classes could not be found:
- android.support.v7.widget.GridLayout

I have restarted Eclipse multiple times and cleaned all projects. Gridlayout_v7.jar is under Android Dependencies and the path is correct.

What should I do to repair the configuration of the project so that android.support.v7.widget.GridLayout can be used?

Computer OS: Windows 8 Pro

CPU: Intel i5

Eclipse (Version: Juno Service Release 2): Build id: 20121004-1855

Hong
  • 17,643
  • 21
  • 81
  • 142
  • try this link http://stackoverflow.com/questions/17020176/java-lang-noclassdeffounderror-com-applovin-sdk-applovinsdk/17020252#17020252 – Sunil Kumar Jul 02 '13 at 16:19
  • Which flavor of Eclipse are you running? I used to run Indigo for my Android Dev. I quick look at their downloads page though and it looks like they have had a bit of restructuring. Eclipse Standard looks like what you want now. – UPGRAYEDD Jul 02 '13 at 16:21
  • @UPGRAYEDD, sorry for forgetting writing my computing environment. I have just added it. – Hong Jul 02 '13 at 16:26

4 Answers4

2

Apparently, you do not have the Android library project containing GridLayout referenced from your project, perhaps because the old reference is now broken.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • the error is from a java file and a layout xml file of the project, not a library referenced by the project. – Hong Jul 02 '13 at 17:11
  • 1
    @Hong: `GridLayout` comes from an Android library project, as you learned that when you set up the project in the first place. Hence, your Java file and layout XML require your project to have a reference to that Android library project. And if that library project reference is now broken due to your upgrade, you will need to fix that (e.g., re-import the library project). – CommonsWare Jul 02 '13 at 17:15
  • Sorry if I am a bit slow in understanding this. My understanding is from a supplementary package. In the Libraries tab of Java Build Path window, there are two jar files under Android Dependencies: 1. androidlibrary.jar and gridlayout_v7.jar. They are not editable. I do not how to fix them. I would love to delete gridlayout_v7.jar, and add it back, but it is read-only. I added GridLayout long time ago, and it had been working fine until this morning's SDK upgrade. – Hong Jul 02 '13 at 17:24
  • 1
    @Hong: An Android library project is not directly related to the Libraries tab of the Java Build Path window. You view your attached library projects via Project > Properties > Android. You can read more about attaching an Android library project at http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject – CommonsWare Jul 02 '13 at 17:27
  • OK. Thanks to your tip, I found the reason. Now, the process of adding GridLayout is coming back to my memory. If I remember correctly, when I added android.support.v7.widget.GridLayout, a project gridlayout_v7 was added automatically to my workspace (does this sound right), and other configuration changes were done automatically (probably including adding an entry in Android Dependencies). I really did not do anything else if I remember correctly. I do not remember of project gridlayout_v7 was added to the libraries. Anyway, I have just added to the libraries, and everything is fine now. – Hong Jul 02 '13 at 17:32
  • Thank you for the tip. I have just taken a look at Android tab and found: Android 4.2.2 is the only target checked. Under library: "Is Library" is unchecked. Here is something strange: there are two entries of gridlayout_v7. Could this be the culprit? – Hong Jul 02 '13 at 17:36
  • @Hong: "Here is something strange: there are two entries of gridlayout_v7. Could this be the culprit?" -- two seems odd. Also, one of those should have a green checkmark -- if one or both have red X's, that indicates a broken reference to a library project. – CommonsWare Jul 02 '13 at 17:39
  • To find out what is going one, I did the following. I removed the two entries of gridlayout_v7 mentioned previously from the Android tab, then removed gridlayout_v7 from the referenced project list. The project was broken again as expected. Then I dragged and dropped GridLayout to a dummy layout file, I got warning " android.widge.GridLayout requries API level 14 or higher, or a compatibility library for older versions. Do you want to install teh compatibility library" I clicked "Install", and saw gridlayout_v7 was added to Android dependency. (to be continued) – Hong Jul 02 '13 at 17:46
  • (continued) However, I still need to manually add gridlayout_v7 project to the referenced project list. – Hong Jul 02 '13 at 17:47
  • thanks @CommonsWare ,re importing the library works for me :) – Varun Chaudhary Sep 01 '15 at 11:20
0

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
0

It probably updated your default support v4 lib and now the on in your projetc/lib folder is probably a different version from the one inside v7.

Delete the support v4 jar file in your project/lib folder.

You can have it there and work with the support v7 lib, but v7 already has a v4 lib and they must have the same version to work.

Remove the v4 jar file in your lib folder, then add the v7.

Dpedrinha
  • 3,741
  • 3
  • 38
  • 57
0

Important Change

It has been removed as of API 25.0.0:

You should replace android.support.v7.widget.Space with android.support.v4.widget.Space


See here

android.support.v7.widget.Space has been removed. Usages should be replaced with android.support.v4.widget.Space.

Mick
  • 30,759
  • 16
  • 111
  • 130