Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Support Libraries to Android project

Why am I having such a hard time getting into the swing of Android development? I've been developing in various languages over the years and, for some reason, just can't seem to get beyond that "jeez-i-still-feel-a-total-noob" stage with Android.

So I'm trying to add an Action Bar to my Android 2.3.3 project. No problem, right? The Android developers website has a nice and clear article explaining exactly how to do it. Of course it involves adding the appcompat v7 support library. No problem, even this is documented step-by-step on this page. But, as with just about every such exercise in Android, I find that you can do exactly what the page tells you to do, it still won't work without significant amount of Googling to fix the errors that you encounter afterwards.

So I've followed the steps under "Using Eclipse" in the section "Adding libraries with resources" in the above link. The first error I get is Unable to resolve target 'android-16'. No problem, this one I could figure out for myself but I'm curious, is there anything in the documents I've been following that would have suggested to me that I need Android 4.1.2 (API16) installed? Did I just read right over it or should I have known by myself that, to do what I'm trying to do, I would need API16?

Never mind, at least I can fix that but then I get a new problem. As soon as I add the android-support-v7-compat library to my project and click the OK button, the console output lights up with errors, the first one being:

C:...\android-support-v7-appcompat\res\values-v14\styles_base.xml:24: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar'.

and the other 60 odd errors are similar but for different given names.

I would really appreciate if anyone could help me out here. Obviously I'd like to know how to solve this particular problem but if anyone could give me some tips on how to get past this very frustrating stage of learning this new development environment, I would be ever so thankful. What is it that I should have done differently not to run into these kinds of errors, other than following the instructions on the Android Developers website step by step?

like image 254
Dewald Swanepoel Avatar asked Aug 17 '13 20:08

Dewald Swanepoel


People also ask

How do I add support to Android?

Downloading the Support LibrariesStart the android SDK Manager. In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder. Select the Android Support Library item. Click the Install packages button.

How do I add a library project to Android Studio?

Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Library Dependency in the dropdown. In the Add Library Dependency dialog, use the search box to find the library to add.

How do I add a support library to my project?

To add a Support Library to your application project: For each module in which you want to use a Support Library, add the library in the dependencies block of the module's build.gradle file. For example, to add the v4 core-utils library, add the following: dependencies { ...

How do I use the support libraries in my Android SDK?

In order to use any of the following libraries, you must download the library files to your Android SDK installation. Follow the directions for downloading the Support Libraries in Support Library Setup to complete this step. You must take additional steps to include a specific Support Library in your application.

How to add external libraries to your Android project?

Almost every well-known Android library is available in a Maven repository and its installation takes only one line of code in the app/build.gradle file: Let’s add the external library to our project: Step 1: Create a new project using Android Studio and name it anything you want (GFG in this example) and hit the finish button.

How do I import a library into Android Studio?

Your library should be available for your project. Click on “ Import Existing Project “. Step 2: Select the desired library and the desired module. Then click finish. Android Studio will import the library into your project and will sync Gradle files. Step 3: In the next step you need to add the imported module to your project’s dependencies.


2 Answers

OK, I guess I should post an answer as I've eventually managed to solve my own problem.

It turns out I have to use a build target of Android 4.2.2, regardless of the fact that I'm specifically developing for Android 2.3.3 - I mean, that's why I'm using support libraries after all. I imagine it might be possible that some other lower target (but higher than 2.3.3) would still work I just used the highest one I have installed and it solved the problem.

How I was supposed to know this from following the step-by-step instructions on the Android Developers website is a mystery to me. The reason I decided to try changing the targetSdkVersion was because of the final section in the page referenced in the question. It reads "If you are increasing the backward compatibility of your existing application to an earlier version of the Android API with the Support Library, make sure to update your application's manifest." Now I'm not increasing the backward compatibility of my existing application. I'm changing an existing application that targets 2.3.3 to be able to include an Action Bar (seems more like "forward compatibility"). I tried upgrading the targekSdkVersion though as I was out of ideas and lo and behold, it worked.

like image 124
Dewald Swanepoel Avatar answered Oct 20 '22 09:10

Dewald Swanepoel


Don't know if it helps you at all, but I've been struggling with a similar issue for several hours and finally managed to resolve it. In my case, inside my own project's styles.xml file, I was referencing the AppCompat style in the wrong way in the parent attribute.

I was using:

<style name="AppBaseTheme" parent="android:Theme.AppCompat">

where I should have used:

<style name="AppBaseTheme" parent="@style/Theme.AppCompat">

My mistake was in the reference to the theme.

like image 24
Matej Avatar answered Oct 20 '22 09:10

Matej