34

I am migrating from Action Bar Sherlock to Action Bar compat. I remove ABS and I had support-v4-google maps in it, I got errors. I will add the v4 directly to the project now to see if it solve, but I want to know:

I don't really understand from the documentation if libraries are redundant or complementing?

Thanks for advice, pointers etc.

EDIT: This is the error that make me added v4 with "external jar... " It solve it.

The type android.support.v4.app.TaskStackBuilder$SupportParentable cannot be resolved. 
It is indirectly referenced from required .class files

But if u say i should not add v4 if already have v7 how do I explain it to Eclipse?

Relevant post, the solution was to add v4 here. The hierarchy of the type activity is inconsistent when extending ActionBarActivity

Edit 2: The v4 jar is included in the v7 library project if done following these steps point by point: http://developer.android.com/tools/support-library/setup.html#add-library My setup is :

  • Android 4.3 : unchecked
  • APrivate Lib: unchecked
  • v7-app.../src : checked
  • v7-app.../gen : checked
  • ADependencie: unchecked
  • raw v7 jar : check
  • raw v4 jar : check
Community
  • 1
  • 1
Poutrathor
  • 1,990
  • 2
  • 20
  • 44

5 Answers5

56

v7 includes the v4 support library so there is no need to have it in there again

if you look in the libs folder of the v7 support library you will see that the v4 jar is already referenced in the library

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • So when I had an error asking for v4 class that I solved adding the v4 library again it was useless, I should have go to each error and make the object change its dependency to android v7 ? Why is there a distinction between the two libraries then and not only one? – Poutrathor Aug 06 '13 at 16:45
  • are you sure you imported the v7 library correctly? v7 is a library project meaning it has resources to go along with things so you cannot just copy the jar file which it sounds like what you did. If you look in the SDk where the support libraries are you will see that v7 contains the v4 jar file so when you import v7 you have the v4 too – tyczj Aug 06 '13 at 16:55
  • I import it following the documentation but you are right I might have failed checking in "order and export". I have: Android 4.3 : unchecked APrivate Lib: unchecked v7-app.../src : checked v7-app.../gen : checked ADependencie: unchecked raw v7 jar : check raww v4 jar : check What do you have ? Why documentation ask to uncheck Dependencies but to check the jars ? We don t check Android 4.3 because it s a library project, right? (god I have so many questions!) – Poutrathor Aug 06 '13 at 17:07
  • Wonderful! It seems to work :) I would still be happy to learn a bit more, if you have the time – Poutrathor Aug 06 '13 at 17:22
  • here http://stackoverflow.com/questions/18271429/difference-between-android-support-v7-appcompat-and-android-support-v4 they say that you need to include both if I understood it right – Thomas Nov 12 '13 at 15:12
  • What about widget.DrawerLayout ? How I should import this package without v4? – user809808 Dec 30 '16 at 13:43
5

V7 is the new version of the android-support library, just something new things implemented in V7 of V4 support library. So the all method and class of v4 are available inside the v7.

So if you add v7 library then no need to add v4 library.

Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50
  • 1
    It would be more accurate to say that V7 depends on and references V4. V7 does not supersede V4. – Nate Cook May 24 '14 at 20:44
  • 2
    V7 is not replacement for V4, BUT depend on V4 https://developer.android.com/tools/support-library/features.html Note: This library(V7) depends on the v4 Support Library. If you are using Ant or Eclipse, make sure you include the v4 Support Library as part of this library's classpath. – Khaled Lela Feb 12 '15 at 07:02
  • What about widget.DrawerLayout ? How I should import this package without v4? – user809808 Dec 30 '16 at 13:43
2

If you are using Android Studio the default way the v7 support library is included is maven dependencies defined in you build.gradle file.

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.0'
}

The appcompat-v7 .aar file does NOT contain the v4 classes. You can see this by looking in your build/exploded-bundles/ComAndroidSupportAppcompatV71800.aar folder. What I have found is that if you create a new project it will also include the .jar file for v4 from the SDK folder.

2

In my case (Eclipse), it depends on which v4 and v7 jar you import in your project.

My suggestion is to use both the file jar present on this folder: C:\adt-bundle-windows-x86_64-aaaammgg\sdk\extras\android\support\v7\appcompat\libs

Alecs
  • 2,900
  • 1
  • 22
  • 25
0

In my case, 'android-support-v7-appcompat.jar' alone was not enough when I used public class MainActivity extends AppCompatActivity in Eclipse. I needed to also add android-support-v4.jar (Build Path -> Libraries -> Add JARs). Only then AppCompatActivity was accepted.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Apostolos
  • 3,115
  • 25
  • 28