android.support.v7.widget.GridLayout cannot get it to work
Asked Answered
S

5

25

I have an android project which utilizes GridLayout in most of its menus and screens. The problem however is that GridLayout is supported from API 14 and onwards.

Since I want to make the application available to older version of android as well, I tried to use Android's own Support Library GridLayout which adds support up to API 7. This was exactly what I was looking for, however I cannot for the life of me get it to work. I have tried all of these explanations and ideas:

  1. Android's official instructions
  2. Solution 1
  3. Solution 2
  4. Solution 3
  5. Solution 4
  6. Solution 5

and more...

No matter what I do, how I do it or what IDE I use (whether Eclipse ADT or Android Studio), it always gives me an error in the Layout XML along the lines of:

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

With either one of these exceptions showing in the error log:

1. android.content.res.Resources$NotFoundException: Could not resolve value 0x7F080000
2. java.lang.classnotfoundexception: android.support.v7.gridlayout.R$dimen

Edit: For reference this is what I'm using to create the support gridlayout (taken directly from the android sample programs):

<android.support.v7.widget.GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/blue"
    android:padding="10dip"
    app:columnCount="4"
    >
    <TextView
        android:text="@string/string_test"
    />
    <EditText
        app:layout_gravity="fill_horizontal"
        app:layout_column="0"
        app:layout_columnSpan="4"
    />
    <Button
        android:text="@string/button_test"
        app:layout_column="2"
    />
</android.support.v7.widget.GridLayout>

What could I possibly be doing wrong that none of the above solutions work? Is there something I'm missing, maybe there's a problem with my original code?

Any help is appreciated

Splenitis answered 29/8, 2013 at 8:39 Comment(1)
@nsvir - added my XML code, though nothing special about it, I used the sample code given by androidSplenitis
H
52

Try using Gradle, and in your build.gradle file add the following section at the end:

dependencies {
  implementation 'com.android.support:gridlayout-v7:28.0.0'
  implementation 'com.android.support:appcompat-v7:28.0.0'
}

Then execute assembleDebug gradle task.

Hornpipe answered 27/12, 2013 at 15:34 Comment(2)
This should be the accepted answer. Importing v24 appcompat and later in ADT (Eclipse) will not work. Build tools are not storing ADT-compatible libraries anymore, and extracting from .aar is too much work - consider moving to Android Studio and Gradle-based build system.Earpiece
With Android Studio 3.0 on wards, instead of compile use implementationAyrshire
T
4

With Android Studio:

  • Go in the build.gradle and add:

    compile 'com.android.support:appcompat-v7:18.0.+'
    

    in your dependencies.

  • Sync your project by clicking the icon on the left of AVD manager. It will implement the library

  • And try again

With Eclipse try this: Gridview v7 support for older api android.support.v7.widget.Gridlayout failed to instaniate

Tamikotamil answered 29/8, 2013 at 8:52 Comment(5)
The code I'm using is running without gradle (while trying to create one via eclipse it shows an error and doesn't do anything), I saw this solution but since I'm not using gradle it's not viableSplenitis
Did you restart your IDE ?Tamikotamil
Yes, multiple times. Tried creating numerous new projects just to test but nothing worksSplenitis
Well I tried on Android Studio and Eclipse by importing appcompat and/or gridlayout and It doesn't work for me neither.. SorryTamikotamil
Thanks anyway, appreciate your help.Splenitis
E
3

For current stable Release 1.0.0 : To add a dependency on GridLayout, you must add the Google Maven repository to your project. Add the dependencies for the artifacts you need in the build.gradle file for your app or module:

dependencies {
    implementation "androidx.gridlayout:gridlayout:1.0.0"
}
Energize answered 19/2, 2020 at 6:20 Comment(1)
this is buggy, causing me lot of issues :\.gradle\caches\transforms-2\files-2.1\834d222cdf56ff4579f6f997b4d0229f\gridlayout-1.0.0\res\values\values.xml:3:5-73:25: AAPT: error: resource previously defined here.Halve
B
2

Refer from http://developer.android.com/tools/support-library/features.html#v7-gridlayout, you should import gridlayout as a eclipse project, then add it as an library project into your project, make sure the build path has included the jar.

Biscay answered 9/1, 2014 at 0:45 Comment(0)
H
1

In my case I fixed it setting:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />

in the gridlayout_v7 project manifest file.

Heartily answered 31/3, 2014 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.