Wednesday, September 4, 2013

How to Run the Android Support Library Samples (Eclipse Version)

 How to Run the Android Support Library Samples (such as ActionBar) in Eclipse

First, make sure you have installed the necessary plugins for Android Development such as ADT.  Here is the official information from Google on how to get the plugins installed in Eclipse.

What are the Android support libraries?  They are .jar files or eclipse projects that let you access the latest features in the Android SDK on older devices such as Fragments (v4) or ActionBar (v7) support.  The v4 library requires a minimum SDK of 4 or Android 1.6, the v7 library requires a minimum SDK of 7 or Android 2.1, and so on.

So you want to support the older Android phones and start by running the support library samples (v4, v7, v13, AppNavigation, ActionBar, etc), but can't find the instructions from Google?  You'll need to download the Android Support Library, create a blank library project, import the existing android code (for v7 support), fix up the created library projects, create a blank project, import the sample demo code, and finally link the support library to your demo.

Also, there is a gotcha to watch out for when using the ActionBar that I experienced where the android:showAsAction values in your menu.xml are ignored and must be set at runtime.  See below for details.

Get the Support Library

Load the support package (and at least API 19) through the Android SDK Manager

After the download is finished, this will be in:{android_sdk}\extras\android\support\
The {android_sdk}\extras\android\support\samples\ folder contains the samples that we will import.  The path to your SDK is listed under SDK Path in the Android SDK Manager tool.
The v4, v7, v13 include the support library for whichever minimum SDK you are willing to support.  i.e. when using the v7 library, the min SDK should be set to 7.  The min SDK should be 13 when using the v13 library.

To install the Android Support v4 Sample Demo

Follow this excellent guide by Tek Eye.  The guide by Tek Eye allowed me to install the samples and get them going, but it did not have an entry for the Android Support v7 Demos, which are a bit trickier to get going.
NOTE: The latest copy of the Android Samples v4 required setting the build target to API 19 or removing the attribute in the Support4Demos/res/drawable/ic_drawer.xml marked "android:autoMirrored='true'"

To install the Android Support v7  Samples Demo

Create a New Eclipse Project to Store the v7 Support Library

You'll be creating a blank project and using this to import the support library as an android library project.  Choose File / New / Android Application Project

Uncheck the 'Create custom launcher' and the 'Create activity' icon, but
Check the 'Mark this project as a Library'

Now, load the support library.  Select File / Import... and choose 'Existing Android Code into Workspace'
Browse to the {android-sdk}\extras\android\support\v7 folder and select Copy projects into workspace if you want.

That will give you 4 new projects in your Eclipse workspace.  But they are not quite ready to use yet.  Also the android-support-v7-mediarouter will have an error that you will need to resolve.

To Fix Up the Android Support Library v7 Dependancies

You should now have 4 new projects:

Expand the libs folder of each library, right-click on each jar and select Build Path / Add to Build Path

Now you will also need to export the jars when projects are linked against this library

Go to Build Path / Configure Build Path and on the 'Order and Export' tab, check the support jars and uncheck Android Dependencies.  Do this for each library: android-support-v7-appcompat, android-support-v7-gridlayout, & android-support-v7-mediarouter.

Now, at this point, android-support-v7-mediarouter will still have a red mark on it with the error: error: Error retrieving parent for item: No resource found that matches the given name 'Widget.AppCompat.ActionButton'.

Link the android-support-v7-appcompat library to the android-support-v7-mediarouter

The android-support-v7-mediarouter has some dependencies on the android-support-v7-appcompat library, so we will need to link the projects.

Click on properties of the android-support-v7-mediarouter project. 
Select the Android page
Add... the android-support-v7-appcompat library

Now do a Project / Clean / All and the Support Library v7 should be clean of errors and your support library is ready to go.

NOTE:  The support library install instructions were adapted from the Android developer page here.

Create a New Eclipse Project to Store the v7 Demo Sample

Choose File / New / Android Application Project

Uncheck the 'Create custom launcher' and the 'Create activity' icon.

Right Click on the project and select Import...  
Pick General / File System

Select the {android-sdk}\extras\android\support\samples\Support7Demos
Check the res, src, and manifest files.

Link the project to the Android Support Library v7:
Click on properties of the SupportV7Demo project. 
Select the Android page
Add... the android-support-v7-appcompat library
Add... the android-support-v7-gridlayout library
Add... the android-support-v7-mediarouter library

Wow, now that all those steps are completed you should be able to compile and install the Android Support Samples to your Android device.

That's it!  The same technique can be used to install the Android Support v4 Library and Samples or the App Navigation Samples.

Note: As one observant reader noticed below, this leaves you with an extra AndroidSupportV7 library project that Eclipse created during the import process that is not used.  You can delete it, or add the libraries above (appcompat/gridlayout/mediarouter) into it so that you only need to import one combined project instead of three separate ones.

General Support Library Notes:

One anonymous comment noted if you are having troubles with a project, check that you have the Target SDK Version in the manifest set to at least 19.  This is found in Eclipse under Project properties / Android / Project Build Target to API 19 or higher.

To use the v7 files, copy these to your project's /libs folder.
  •     android-support-v4.jar
  •     android-support-v7-appcompat.jar
  •     android-support-v7-gridlayout.jar (*if needed)
  •     android-support-v7-mediarouter.jar (*if needed)

Typical gotchas for people:
  •     Make sure the min SDK is at least API 7
  •     Make sure the project target build is at least API 19

What to do next:

To learn more about database and network usage with android, check out the WorxForUs Android Database and Networking framework tutorial that assists database access and network access and addresses several common pitfalls.

Hope you found this guide useful, please drop a note, funny internet cat picture, or +1 if it helped.

ActionBar Gotcha Notes:

If you have trouble getting the ActionBar to display icons instead of just overflowing, check where you are setting the showAsAction values.  In the menu_layout.xml, the showAsAction attribute is ignored when using the support library and won't work.    <item
        android:showAsAction="ifRoom" //this will not work

To fix this, add the show as action items in the options menu creation function
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(, menu);
        MenuItem add = menu.getItem(0);

        //Set the show as action value here at runtime
        MenuItemCompat.setShowAsAction(add, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);


  1. Thanks for this. THere seems to be a small typo in the third last paragraph:

    Select the {android-sdk}\extras\android\support\samples\Support4Demos

    be Support7Demos?

  2. Yes, it should - I'll update the instructions to correct it. Thanks for the note, Andrew.

  3. Hi,
    thanks for this how to. Now this finally works. That's great but I do not get why do you need your own support library project (i.e. AndroidSupportV7). I can not see any connection between the Support7Demos and the AndroidSupportV7 project.

    1. You're right, you don't need it. There is no connection between AndroidSupportV7 and the Support7Demos. It's an artifact of how I imported the project with Eclipse. By doing that we only had to import once instead of 3 times (once for each sub-project), but it leaves us with an extra library that is not used.
      You can delete it, because the sub-libraries v7-appcompat, v7-gridlayout, & v7-mediarouter are all that you will need.

      Thanks for reading!

  4. HI,
    I followed the steps exactly but still 'mediarouter' has the following errors:

    error: Error: No resource found that matches the given name (at 'paddingEnd' with value '?android:attr/listPreferredItemPaddingEnd'). mr_media_route_list_item.xml /android-support-v7-mediarouter/res/layout-v17

    error: Error: No resource found that matches the given name (at 'paddingStart' with value '?android:attr/listPreferredItemPaddingStart'). mr_media_route_list_item.xml /android-support-v7-mediarouter/res/layout-v17

    error: No resource identifier found for attribute 'paddingEnd' in package 'android' mr_media_route_list_item.xml /android-support-v7-mediarouter/res/layout-v17

    error: No resource identifier found for attribute 'paddingStart' in package 'android' mr_media_route_list_item.xml /android-support-v7-mediarouter/res/layout-v17

    1. Version 17 of the support library and API 17 introduce the paddingStart/End that you are having trouble with. Check that you have the API 17 SDK downloaded from the Android SDK Manager.

      The android-support-v7-mediarouter depends on the android-support-v7-appcompat project, check that the library reference is set in the Eclipse Android project properties and that android-support-v7-acccompat compiles properly.

      Your projects should target API of at least 17 and min SDK of at least 7.

      You may just need to do a clean all.

  5. Still the mediarouter showing error on Layout-v17

    how can i fix this , Please help

    1. When you right click on the project and select Properties / Android, which Project Build Target do you have selected? Are you having the same problem as anonymous?

      I wonder if someone else is also having this problem. Since the error references the v17 it leads me to think that the project is having trouble finding the API17 files. Post your error console if possible.

    2. Hey, I had the same issue and fixed it by changing the "Project Build Target" to "Android 4.2.2" or higher in the project properties. You can change it by right clicking on the project, clicking properties, clicking Android in the left pane of the new window, then checking the appropriate option. Like the poster said, mediarouter requires API 17+, so picking any of those should work. Happy programming :)

  6. thank you for this tut . but how can use this SupportV7Demo project in my own project that support android 2.1 and above ?

    1. The recommended way of getting the base support library into Eclipse projects is to Right-click on your project, go to Android Tools / Add Support Library...

      You can also copy the android-support-v7-appcompat.jar, and other v7+ support librarys into your project from where you have the SDK installed at \android-sdk-windows\extras\android\support\v7

      Note: If you are using the v7 support package your min SDK in the manifest must be API7 which is Android 2.1. You can go as low as 4 if you only use the v4 support package.

  7. thank you very much

  8. Add to this the various vendors providing different phones with numerous variations of hardware components means that most developers have nightmares developing code for each individual phone rather than a universal app.gerald winata gozali

  9. best roti maker. Still the mediarouter showing error on Layout-v17

  10. est place you have ever met. Best sad shayari

  11. Awesome Blog!!! Thanks for sharing this data with us... oracle training in chennai

    Email is a personal way of making contact to your prospects. And since it is a private message, trust and connection are built already. purchase email lists The conversion rate is also higher compared to mainstream media due to low operational and overhead costs. On top of that, email is easier to monitor and evaluate than printed materials. Through email marketing, you can jumpstart your b2b lead generation regardless of what type of industry you are in. The first step to buy email list for marketing is choosing the right email list provider. You need to buy email list to get ahold of the valuable information of your would-be clients for your brand. In this way, it will be easier for you to search for businesses, find contact persons and decision makers and go about your product and services.

  13. Internet Download Manager Crack ed Download
    If you cannot afford to purchase the Internet Download Manager sequential number in the (moment), then it is possible to readily download the online download manager crack version. Don't stress IDM Crack can also be full edition, you may down load the deciphered IDM from the URL given below or you need to utilize IDM serial number to register the online downloadmanager.
    Once we know, there are many IDM busted models are available and also the Internet download manager limitation is also available. Still, if you are a person who can readily afford the applications, then you must purchase the applications as it ailing help the programmers to pay for their bills also to spend the money generated by sales of the Internet download manager or even IDM crack full variant in making the software easier and much more useful because new features also cost the company in execution and research. You can purchase the original IDM full variant through their official site.

  14. AirBNB management services in Dubai is a DTCM licensed holiday home Operator managing vacation rental villas and apartments for short and mid term stay in Dubai.

  15. Friendly Finance is South Africa's number 1 choice for finance - providing customers with all the information they need to make better financial decisions. friendly finance We provide hundreds of comparisons of common consumer finance products, such as personal loans, car loans, short-term loans and credit cards. Think of us as a helping hand in selecting consumer finance products.

  16. Recently, the keto diet has become extremely popular for its health benefits such as weight loss and preventing disease. A custom Keto plan for life! Visit here: how does the keto diet work

  17. Find the perfect handmade gift, sana sana rana vintage & on-trend clothes, unique jewelry, and more… lots more.

  18. - Como organizar sua Semana com o Taskade - Segunda Feira, primeiro dia.
    - Como organizar sua semana com o Taskade - Terça - Vlog de Produtividade
    Como organizar sua semana com o Taskade - Quarta
    - Como organizar sua semana com o Taskade - Quinta - Vlog Produtividade.
    - Taskade - Sexta, Sábado e Domingo. Como foi e uma grande novidade

  19. ac repair and services in bachupally Extend the Lifespan of Your System with Proper Maintenance Like all machines, air conditioners benefit from regular maintenance; we know that for a fact.

  20. wonderful article contains lot of valuable information. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    This article resolved my all queries.good luck an best wishes to the team members.continue posting.learn digital marketing use these following link
    Digital Marketing Course in Chennai

  21. Impresión online en gran formato, Photocalls personalizados imprimimos roll ups, photocalls, vinilos, lonas. Envío gratis

  22. Health Experts have proven that regular exercise coupled with a good diet allow you to live longer and healthier. In this busy day and age, not everyone has the time to go to the gym - resulting to a lot of overweight people that desperately need to exercise. A healthy alternative is for you to Buy Home Gym Equipments that you can store in your own home or even at your office. Here are some tips when buying home gym equipment.

    First, know your fitness goals and keep these goals in mind when you are buying home gym equipment. One of the biggest mistakes that people make is buying the biggest or trendiest fitness machine simply because they like how it looks. More often than not, these end up gathering dust in your storage rooms or garage because you never end up using them. It is important to take note of what particular type of physical activity you want or enjoy doing before you buy your exercise machine. If you are looking to loose a few pounds and you enjoy walking or hiking, a treadmill is the best option for you. If you are looking to tone your lower body while burning calories a stationary bike is your obvious choice. Similarly, Special Equipments for Core Strength Exercises, Strength Training Weight Vests, Core Strength & Abdominal Trainers, Home Cardio Training, Strength Training Power Cages, Strength Training Racks & More.

    Second, set aside a budget before Buying Home Gym Equipments. Quality exercise machines do not come cheap. They are constantly exposed to wear and tear when they are used properly. So, pick machines that are built to last and have passed quality certifications to get the most out of your money. If you are operating on a tight budget, think about investing in several weights, We can Provide you High Quality Home Gym Equipments at Very Low Prices for your Complete Uses: Core Strength Exercises, Strength Training Weight Vests, Core Strength & Abdominal Trainers, Home Cardio Training, Strength Training Power Cages, Strength Training Racks & More.

    Its the Right Time to Buy Home Gym Equipments for you at Very Low Prices.

  23. We are a clean skincare brand, 100% organic and made with what the earth has given us first. Our product formulations came from listening to our ingredients. From their benefits, scents and results, our products are truly science of the earth. We wanted to step back from the long list of hard to pronounce scientific gibberish and provide ingredients relatable and understood. We are very proud to be one of the first few on the market to be ECO-Certified under the COSMOS standards, and for us we want to leave the earth better than we found it.

  24. Are Anabolic Steroids and Body Building Supplements Safe to Use?

    Anabolic steroids and lifting weights supplements are a questionable way that numerous competitors and jocks to construct muscle. Frequently alluded to as these steroids, these enhancements are introduced in both regular and engineered structures. Heaps of the debate concerns the engineered structure because of the destructive results that weight lifters can experience the ill effects of. Characteristic anabolic enhancements will in general be less destructive whenever utilized with some restraint. In any case, Alpha pharma Anabolic steroids advance cell development and division, which is the regular standard behind weight training since it causes enormous muscles framed from more modest ones.

    Lifting weights Supplements have been demonized by a standing for an assortment of reasons. At the point when competitors and maltreatment of anabolic steroids muscle heads, they acquire an upper hand over their rivals. Thus, authorities in the game of cricket to weight training thought about anabolic steroids and enhancements contrary to the guidelines. This is apparent in the new outrages identified with baseball whizzes like Barry Bonds and Mark McGwire. During the 1980s, the World Wrestling Federation additionally experienced a major embarrassment that prompted the utilization of anabolic steroids and enhancements in the news. These and different outrages have added to the helpless standing of these questionable anabolic enhancements.

    Training on the impacts of anabolic steroids and enhancements is important to help direct individuals from them. Sadly, large numbers of the competitors in secondary school have gone to anabolic enhancements to help them acquire an upper hand against their rivals. With the constructive outcomes that are depicted by proficient competitors, more youthful clients are regularly unconscious of the ramifications as long as possible. Numerous anabolic steroids supplement clients experience the ill effects of hypertension, which can prompt a lot of genuine ramifications and can't be fixed on the body of the client.

    Despite the fact that steroids identical to a lot of debate, it isn't liberated from results positive. In the event that you need to assemble muscle quick, anabolic steroids and enhancements is one approach to do as such. They were additionally utilized in an assortment of clinical medicines until it was restricted in 1988. Pediatricians utilized anabolic to invigorate development in kids with hindered development chemical. Specialists likewise have utilized steroids to help malignancy and AIDS patients increment their hunger and fabricate bulk. Up to this point, specialists additionally used to prompt pubescence in young men. Presently, clinical medicines use testosterone for this reason and to assist competitors with recuperating wounds.

    Enhancements of manufactured steroids are dubious on the grounds that they give expanded strength and bulk, yet at extraordinary expense to the wellbeing of the client. The normal way, in any case, might be less hurtful. Regardless, even common anabolic maltreatment can be inconvenient to their wellbeing and bodies. By and large, can be the master or mentor to exhort you and assist you with finding the most valuable type of lifting weights material to assist you with accomplishing the best outcomes.

  25. Buy Modafinil Online – Buying pills like Modafinil is not easy. Are you trying to purchase modafinil online? If your answer is Yes, then you are in the right place. In this buyer’s guide, we are going to cover everything you need to know about the most popular nootropic in the world.

  26. Why Your Online Business Needs A WordPress Website

    The WordPress site framework is currently the most generally utilized site building stage on the web, with more than 22% of all dynamic areas utilizing it. This site program has the usefulness to assist your online business with procuring income also giving as a total substance the board framework.

    There are in excess of 75 million WordPress sites on the web and it is supposedly utilized by numerous lofty associations. On the off chance that it is adequate for them, it will doubtlessly be sufficient for your online business.

    A Flexible Website Builder. wordpress ecommerce templates

    WordPress is an entirely adaptable program for an online business. You have the choice to post customary news things onto your site and make explicit item deals pages. You can decide to permit remarks on your pages which makes client created content as peruser's remarks. Updates can be planned for advance so that pages can go live at a pre-decided time and you can make certain pages private so just your clients with the particular URL can get to them.

    Creator Management.

    The program permits you to have numerous clients with various degrees of power. You can let others to make and add substance to your site without giving them full access rights to the whole site situation. You likewise can check and support any updates before they go live.

    WordPress Website Templates.

    At the point when a guest lands on your site, you just have seconds to dazzle them and convince them to remain. With the site layouts (called subjects) you can transfer an immense wide range of topics at the snap a catch. A few subjects are free and some have a little expense and there will be a topic that gives the look and highlights that you need for your online business. You can likewise effectively review and trade between subjects to see which one you like best.

    A WordPress Website Design To Suit You.

    The fundamental site download is a minimal programming system and you do have to add the additional items, or modules, to expand your site's abilities. Numerous modules are free and permit you to do various things including the formation of mailing records, contact structures, connect following, site design improvement frameworks, site investigation and the sky is the limit from there.

    Since there are so numerous WordPress sites on the web there are individuals everywhere on the world who create additional items, modules, topics for you to download to your site. What was once utilized for publishing content to a blog has now developed into an exceptionally incredible program to assist you with making a site that will attract the traffic and bring in cash for you.

  27. If you're looking for free movies online feel free to visit the site. free online streaming website You can watch unlimited movies and tv shows without any registration. Bazflix has thousands of movies and tv shows online.

  28. Bigg boss is a Telugu TV Reality Show. Here we provide daily episodes reviews, insights, share Opinions, Facts and Gossips around Bigg Boss Telugu. biggboss 5 telugu

  29. BCT Consulting is proud to announce a new location in century city California. For the past decade, we have been providing web design, IT support los angeles managed IT support, and cyber security services to some of the biggest brands in Los Angeles.

  30. Infycle Technologies offers the Best Data training in chennai and is widely known for its excellence in giving the best Data Science Certification course in Chennai. Providing quality software programming training with 100% placement & to build a solid career for every young professional in the software industry is the ultimate aim of Infycle Technologies. Apart from all, the students love the 100% practical training, which is the specialty of Infycle Technologies. To proceed with your
    career with a solid base, reach Infycle Technologies through 7502633633.

  31. career towards a sky-high with Infycle Technologies. Infycle Technologies provides the top Oracle DBA Training in Chennai and offering programs in Oracle such as Oracle PL/SQL, Oracle Programming, etc., in the 200% hands-on practical training with professional specialists in the field. In addition to that, the interviews will be arranged for the candidates to set their careers without any struggle. Of all that, Cen percent placement assurance will be given here. To learn Oracle DBA for making the best job for your life, call 7502633633 to Infycle Technologies and grab a free demo to know moreNo.1 Oracle DBA Training in Chennai | Infycle Technologies