19

I want to add GridLayout into my android project which is use support library GridLayout v7. I found this thread but maybe a few steps of adding this library did not mention in this paragraph Set up support GridLayout library in IntelliJ.

can anyone explain obviously?

Edit: I have the same problem at this thread

3 Answers 3

47

It's late for an answer but here it is, at least for future people looking for a solution on how to add the support library and resources for GridLayout (or ActionBarActivity / AppCompat, see below).

The easiest way is as follows.

  1. Make sure you have installed the Android Support Library, from the Android SDK Manager. enter image description here

  2. In IDEA: Open your project, then select File / Import Module

    • select the directory under the SDK: {SDK}\extras\android\support\v7\gridlayout enter image description here
    • select Import module from external model and Eclipse
    • you can then select Create module files near .classpath files, or choose to put them elsewhere if you can't / don't want to write into your SDK path
    • in the next screen you should see Select Eclipse projects to import and android-support-v7-gridlayout, IDEA will also ask you to reload the project.
    • this should add a module gridlayout [android-support-v7-gridlayout] in your project.
  3. Now you have to update your project dependencies to this module for the resources, and add the .jar libraries. Select File / Project Structure

    • select the Modules project settings, and select your project (in the picture below, testv7)
    • select the Dependencies on the right panel
    • add with the + button (on the right panel) a Module dependency... to the android-support-v7-gridlayout enter image description here
    • similarly, add a Jars or directories... pointing to the {SDK}\extras\android\support\v7\gridlayout\libs directory (or to the .jar within). If you intend to use the v4 as well, choose {SDK}\extras\android\support\v7\appcompat\libs instead since it contains both v4 and v7 jars
    • your settings should look like this: enter image description here

And now you should be fine.

For me it was the only way out of the similar problem with the ActionBarActivity, which is solved using the same technique on the {SDK}\extras\android\support\v7\appcompat module. And I did try a few other ways ;)

4
  • 1
    Thanks I just switched from Eclipse to IntelliJ and this helped me to add the appcompat library to the project I'm working on.
    – joelreeves
    Dec 17, 2013 at 4:19
  • 1
    wow I spent the whole day trying to figure this out. I would give +5 if I could. Thanks for the thorough instructions.
    – Eric H.
    Jan 1, 2014 at 1:42
  • You're welcome, that took quite some time to figure out too :)
    – RedGlyph
    Jan 18, 2014 at 17:18
  • 1
    Also: make sure you have enabled Eclipse Integration plugin (I never used it, and had it turned off, and couldn't understand why I have only gradle and flash to choose from) and make sure order of dependencies is set properly (I had library above module sources and it was failing with a weird error - on generating R.java). Also, for me adding libraries that way didn't work, I had to put them in the libs directory inside my main module (and then add them to dependencies). I can't believe how many traps it has...
    – trakos
    Mar 31, 2014 at 6:32
16

Today I struggled with this and on android dev site I found simpler solution and why they're problems with it. GridLayout from v7 libraries aren't connected with v7 appcompat library so you must add v7 gridlayout library dependency manually.

If you use gradle then in build.gradle just add

dependencies {
    ...
    compile 'com.android.support:gridlayout-v7:23.1.+'
}

and everything should works fine :)

2

If you are using Android Studio, just go to Gradle Script -> build.gradle(Module:app) -> dependencies and type those dependencies there for better support.

compile 'com.android.support:gridlayout-v7:23.0.2'
compile 'com.android.support:appcompat-v7:+'

P/S the "v7:23.0.2" depends on your lastest build tools..

Hope this will help..

2
  • Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually wont help the OP to understand their problem. Aug 18, 2015 at 14:37
  • He's not using Android Studio. He's using IntelliJ Jan 20, 2016 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.