Now I know that this question has been asked many times but the solution that has always been proposed has not worked for me. It has been said that the minimum SDK version has to be greater than 10 in order for showAsAction to be used. In my manifest file, I have set my minimum sdk at 17 and my target sdk at 17. What else could be causing this error? Here is my menu's XML file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Text2Morse="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/SettingsID"
Text2Morse:showAsAction="ifroom"
android:icon="#drawable/ic_gearl"
android:title="#string/MySetting">
</item>
<item
android:id="#+id/ReadMeID"
android:icon="#drawable/ic_readmel"
android:title="#string/Read_me">
</item>
Could it be that the support library is not properly included on the build path? To include the support library on the build path I was following the steps posted on the android development website:Support Library SetUp
I got through the first part alright but when I get down part that says "Add the library to your application project" things don't work.
Directions
For example, on step 2 for this portion of the directions it says "In the Library pane, click Add". I do not know what program they are using but I am using eclipse. There is no add button in the Library tab for me. There is only add jars, add external jars, add variable, add library, add class folder, add external class folder. There is an add button in the Projects tab but this is not the Library tab. I have even experimented by assuming that the directions really mean to refer to the project tab and following the steps from there. I add the Support Library project folder but I still see the same error.
All I want is for some of my menu items to show up on the action bar. Can someone help me out here?
I spent forever trying to make this work in the XML, and never could. I suspect a problem with build path and the support libraries.
I was able to make this work by setting the flag in Java instead:
menu.add(0, MENU_FULLSCREEN, 0, "Fullscreen").setIcon(R.drawable.ic_action_fullscreen).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Related
So I am just starting to learn to program with Android. Everything works great (I'm using Eclipse as IDE by the way). I only had this problem. Every time I make a new project that I chose API 8 as the Minimum required SDK, and chose a theme (Holo Light with Dark Action Bar for example), Eclipse will ALWAYS import a NEW COPY of the Android Support Library v7 (appcompat). I know this is required for the ActionBar and Fragments on old devices (API 7 - 10). But what I don't get is why Eclipse has to import a new copy of the support library all the time (well I'm just starting to learn and I am thinking that the support libraries can be and is meant to be edited, I'm not sure).
So due to this, I made my own solution. I followed what is said here from the Android Developer website. I imported the support library to my Eclipse workspace by myself. Then I created a new project. So, Eclipse (once again) imported it's own appcompat-v7 support library. I deleted it and then on the Properties of my project, I replaced the deleted appcompat-v7 library with my own-imported v7 library I added earlier.
This could have been a solution, but I encountered some problems
Eclipse added a new package in my PROJECT_FOLDER/gen named from the Support Library I imported manually, and as a result (which I don't understand why), it creates it's own R.java file (which causes a name collision-like effect). That is, when I mention something like this on my code, the R.java file that is searched was not the right R.java (but the duplicate R.java file)
EditText editText = (EditText) findViewById(R.id.edit_message); // this shows an error because the duplicate R.java file contains different fields from what the project's R.java file have
Another thing, when I create a new Activity, many errors are popping on the Eclipse Console like
[2014-04-08 14:53:49 - MyFirstApp] C:\Users\ME\Documents\Android\Android Workspace\android-support-v7-appcompat\res\values\attrs.xml:572: error: Attribute "textAllCaps" has already been defined
Additionally, the project will import AGAIN the appcompat-v7 library that it imported earlier (which I manually deleted) AND it will delete my R.java file AND will unassociate itself with the v7 library I manually created.
Is there a right way of doing this? Or the Support Library is really needed to be imported always? Thank you.
I faced the same problem when accidentally recreating the MainActivity. As a result it imported a new reference to the Appcompat libraries.
You see these errors because there has been duplicate reference to the reference to the Appcompat libraries. Do not delete anything yet.
First thing you must do is remove the duplicate reference by right clicking on your project or press Alt+Enter to show the project properties window. Then click on Android tab and go to Library.
On the list of referenced libraries, you will likely see more than one reference to the Appcompat library. Select one and click Remove then click Apply and OK.
You can then the unwanted MainActivity activity, its layout and menu XML files. But be sure to take extra care.
I hope this helps.
right click on project, go to properties, go to android, and then remove all app
I'm using android-support-v7-appcompat as a library in my Android project. Now I want to include actionbarsherlock as another library project. When I add the second library, it gives so many errors like below
android-support-v7-appcompat\res\values\attrs.xml:476: error: Attribute "attributeName" has already been defined
By changing one attribute value and it's related code snippet is a one solution that I've tried. But when there are nearly 80 lines like above, it will get a messy. Is there any other way I can solve this issue?
The correct way to solve this problem is by updating Android Support Libraries in all relevant projects and library projects. In my case I've used Android support library and also one of the library project to implement my application. When I update both libraries, the problem solved. The way of updating Android support library is;
Right click on the project
Select Android Tools from the pop up window
Select Add Support Library
Remove the appcompact support library project from Properties = > Android
Gradle Resource Merger merges all resource folders from all dependencies and place into single folder. In case there are duplicates build process will fail.
Fortunately, if you look below under Output: label, you will find the right path to the problem.
Here is an example
in your case it is
android-support-v7-appcompat\res\values\attrs.xml:476: error: Attribute "attributeName" has already been defined
You can also build your project from command line and get the right path.
attributeName
Inside values\attrs.xml file on line 476 you would find a with property named "attributeName". Most probably it is your own styleable that you have to change to get rid of the duplicate.
So now, when you know the reason, you can locate that property in your project module and replace it with different name.
I solved this by removing appcompact from project, and changing in styles to
<style name="AppBaseTheme" parent="Theme.Sherlock">
I updated the build tools version and resynced, it worked fine.
I have download this custom datepicker:
https://github.com/flavienlaurent/datetimepicker
I'm new to Eclipse and Android.
How should I use this?
When I import, I get an error at res folder.
http://i.stack.imgur.com/Dh7df.jpg
Please help me.
Sorry for asking a noob question.
Thanks
I've imported the datepicker to my Eclipse and I can to build it without any error.
Have you downloaded all the necessary Android SDK files using the Android SDK Manager? I see your 'MainActivity' is having compile error too.
Edit:
From the errors, seems like the attributes buttonBarStyle were only defined starting in API Level 11.
There are a few ways to solve this.
1) Set your app and the library project minSdkVersion in AndroidManifest.xml file to "11", this will make your app not be able to use on older Android versions though.
2) Move this particular layout file to res/layout-v11/ folder, and create another version of the same layout file in res/layout folder, but doesn't use the buttonBarStyle.
3) Seems like there's a way to create a attr.xml file in res/layout, and define the attributes manually. I have not tried it personally though you might want to try.. refer to error: Error: No resource found that matches the given name: attr 'buttonBarButtonStyle'
Good luck
Edit2:
Changing android:minSdkVersion="11" and android:targetSdkVersion="17" in your datetimepicker AndroidManifest.xml file should work!
From your screenshot, I saw that it doesn't recognize "HONEYCOMB", seems like your ADT version is not the latest, please try update it to the latest first.
After that right click your datetimepicker-library project in Eclipse, click 'Properties', then go to 'Android' tab, you should see API 15 or above checked, for mine I have API 17 checked as shown here http://i.imgur.com/Z3DkRY1.png
I think your eclipse is not configured properly
Just ran in the same problem. In order to use this library make sure that:
Datetimepicker-library references NineOld Androids
Project properties, Java build path, Libraries contains android-support-v4 and order and export has this jar checked
Project properties, Android, project target build is set to API 19 for example
The last one was causing most of the problems. If you set it to a higher target build, that does not mean that it will not run on lower API levels.
I have a project target to API Level 10 and i want to implement the new ActionBar support library.
After follow all the instrutions in the Support Library Setup, when adding the library to my project I came across with dozens of error messages like this:
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.....
OK, i know that they are many answers to this question, but, after trying all the more obvious, i still could not solve the error.
I kept searching and found the cause, which is not so obvious, at least for newbies like me.
My intent is provide a full answer to help all those who are like me and do not master all the secrets of the Android development.
This is what you have to do for use the ActionBar support library correctly.
Follow the instructions in the Support Library Setup - Adding libraries with resources.
One thing that can bring some doubt is add the library to your aplicattion project:
(1) In the Project Explorer, right-click your project and select Properties.
(2) At the left pane select Android.
(3) At th bottom of the right pane click Add
(4) Select the library project android-support-v7-appcompat and click OK.
Click OK to close the properties window.
If you not get any of the errors I mentioned it´s all done.
However if you are like me, you dont´t followed the advice of Android team that suggests you always compile your source using the latest SDK, you get the error.
The error ocurrs because my Project Build Target was Android 2.3.3 and need to be at lest 3.0.
It was not immediately clear to me because of the fact that I'm specifically developing for Android 2.3.3 and I'm using support libraries.
OK, I hope this helps.
You should add that support library to your project. To add:
Right click on project, then go to :
properties > Java Build Path > Libraries
here Add External JARs...
add android-support-v7-appcompat.jar (path/to/sdk/extras\android\support\v7\appcompat\libs)
Additionally you also have to copy that jar to libs folder of your project, if it is not there automatically.
and you should use the #style/Theme.AppCompat theme for your application for support-v7 to be working
also keep one thing in mind you should change min sdk version to 11 if you want to support("android:windowActionBar")property in your 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?
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.
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.
I found that setting the Android target to 2.3.3 for the library project android-support-v7-appcompat solves this issue. You don't need to set your project's target higher, but the library's target lower.
You have pinpointed the all important document and the relevant section "adding libraries with resources":
http://developer.android.com/tools/support-library/setup.html
The error suggests that your project is not able to find these resources. Please double check the following :
You have checked "is library" on the library project
You have exported the jars IN THE LIBRARY PROJECT as described in that section
You have added the library project as a reference to your app project
You have added the android-support-v4.jar to your libs folder in your app project
If this is all definitely correct, check eclipse for any error messages - is it the library project or the app project that lights up like the proverbial Christmas Tree ?
First of all check if you have done all the described steps as explained on the developers site. Then, for the errors :
Unable to resolve target 'android-16'
Make sure that you have installed API16, this errors occurs if you have mentioned your targetsdk to 16 in your Manifest while the sdk for API16 is not installed. You can either install the API or edit the targetApi of your project to the minimum required version, for the support library you are using I think API 11 is the minimum required android version.
android:Widget.Holo.ActionBar
This error should also be fixed once the targetsdk is fixed in your project. Since to use Holo.ActionBar you'l need to target your project to minimum supported api level ie. 11 or higher.
I met similar problems. Using API 18, ADT.
To solve the "Unable to resolve target 'android-16' problem", I remove the import lib project and repeat what the tutorial says.
Then I found I couldn't really "add" the library to my project. (The instruction "In the Library pane, click Add." there is not that detail.
1. In your project -> properties -> Java build path -> Libraries -> Add Library... -> Android Classpath Container -> Select the lib project
2. In your project -> properties -> Android -> add... -> choose the lib -> apply
cheers
Here is how I avoided the error, " Unable to resolve target 'android-16'", when adding v7.
First, I followed the instructions for adding support libraries with resources in eclipse. Following step 4, I clicked Finish. That's when I saw the error message, android-support-v7-appcompat] Unable to resolve target 'android-16'.
Second, I read this post. I also opened the download manager, but did not need anything updated. In order to make sure that I followed the steps exactly as correctly as I could, I deleted the android-support-v7-appcompat project and started over.
This second time I didn't check any different boxes, after all. But, I also got no errors at step 4. Who can say why?
Thanks, Dewald, you expressed in this question the same frustration I have. Is experience the only way out?
If some of your resource xml files cannot find their respective AppCompat references, make sure you also add the support libraries to your project properties. You do this by:
1.) right clicking on your project in the project
2.) Select properties. (Bottom of the menu)
3.) click Android on the left hand side menu of the new pop up window
4.) In the libraries section, click the "add button"
5.) Select the respective libraries. (If none show up, check to see if they are already displayed in the "libraries" window of the pop up menu. If there is a red x by the desired library, try and resolve that issue first.)
6.) Once there is a green checkmark next to the desired libraries, make sure the "Is Library" option in the libraries section IS NOT selected.
7.) Click apply.
8.) Close the pop up menu.
If this doesn't work, let me know and I can help you out. I spent three hours on the problem so I know pretty much all the possible things that can go wrong with the set up.
Go to Project -> uncheck Build Automatically
Go to Project -> Clean... , clean both the library project and your app project
Export your app as a signed APK while Build Automatically is still disabled