Question about version specific resource file - android

My application support up to the sdk version 21, but I have some styles that work only for SDK 23+.
Should I only add a SDK 21 specific styles.xml, or should I also add a SDK 22 specific styles.xml ? Because they share the same problems.

No, you just need a general styles file, and a 23+ styles. Then anything below 23 will use the general file, and anything 23 or higher will use the v23 one.

Related

no resource identifier found for android:elevation

As per guidelines here for Android L development, I used android:elevation property in my application, but it shows the following error:
No resource identifier found for attribute elevation in package
android
I am using eclipse and I have downloaded the latest version just 2 days ago.
I have also set my target sdk as API level 21 and minimum as API level 14. I have also installed the latest updates on sdk-build tools shown in sdk manager.
Anyone know the solution? plz help me.
1) Select Project > Right Click > Properties > Check Android L > apply > Ok
2) android:minSdkVersion="L"
Hope this will work for you.
One thing worth noting is that Android Lollipop corresponds to API level 21. There is no such thing (yet) as API level 22.
You should be able to solve your problem by setting android:minSdkVersion and android:targetSdkVersion to "21".
Select Project, then Properties, then Android and tick Android 5.0. Ignore all the answers telling you to set android:minSdkVersion. Android is designed to ignore stuff inside elements it does not understand just so that in this case you can apply elevation when running on lollipop devices and it is ignored on earlier devices.
You can hide the remaining lint warning in the xml file by adding tools:ignore="NewApi" in the element. This needs xmlns:tools="http://schemas.android.com/tools" specified in the root element.
AppCompat v21 allows a fair bit of Material Design to be used on pre-lollipop devices, but I've yet to work out how to add it to a project in Eclipse.
android:elevation or View.setElevation() is introduced since Android API 21. So, if you set android:minSdkVersion="14", it's not OK. android:minSdkVersion="14" is integrant.

confusing about android minSDK

I have a question about minSDK. I took a project example in here: Contacts Providers.
This project has a minSDK = 5. And in styles.xml some attribute which require higher sdk version like:
android:textAllCaps --> min 14
android:fontFamily --> min 16
But that project so no any error and run fine.
When I copy some style into my styles.xml in my project. It causes an error:
android:textAllCaps requires API level 14 (current min is 11)
...
Can someone help me with the compile error?
You can use those styles in the respective minSDK version by using resource qualifiers. In your resource directory: there is base styles, add folders to res/styles-v14 (for use in ice-cream sandwich and greater, where minSDK is 14) and styles-v16 (so on so forth if you need the styles to be applied when available)
Now when the style needs a higher SDK version, place it in respective style resource directory. textAllCaps goes into styles-v14, android:fontFamily goes into styles-v16.
More can be found here on resource qualifiers ;)
http://developer.android.com/guide/topics/resources/providing-resources.html
Hope this helps buddy, happy coding!
EDIT: previously misunderstood the question/scenario. Sorry!
I think the problem is your Target API level. Make sure that the target api level is at least the level in which the APIs were introduced. In this case, 14.
If you build from command line you would just do
android update project -p -t
(I think what the command does is just update project.properties and sets target=android-14)

Android Styles and Values issue

My Android project was working fine when I noticed that I had checked SDK version 4.2 when I meant to target Google 2.33. I set the project back to G2.33 (In the manifest it minsdk = 8 targetsdk=11) and now I have errors on two different styles.xml files in two folders named Values-v11 and values-v14.
the styles.xml in the Values-v14 folder has an error on the following line...
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
the st yles.xml in the Values-v11 folder has an error on ...
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
My other projects, that all target 2.33 don't even have these folders. What is the best way of me getting out of this mess?
Thanks, Gary
You could simply delete these folders if you don't want anything specific for SDK level 11, and the one for 14 won't be used anyway if your targetsdk is 11.
If you want to retain the one for api level 11 for custom behaviour in API level 11, you need to set the project to compile with API level 11 - i.e. if in Eclipse, select the project, go to Properties, select Android and then set the project build target to "Android 3.0" or "Google APIs" for API level 11 if you need the Google APIs.

Android XML Style/Theme Version Compatibility, Considering Development Safety with Eclipse/lint

It appears the best way to develop an Android application today is to target android-17 in project.properties along with minSdkVersion "whateversuitsyou" and targetSdkVersion 17 in the manifest.
In this configuration, the standard lint checks will notify about any API calls which are only available in API versions above "whateversuitsyou" and one can use reflection etc to dynamically support the newer features, if any.
However, in this setup, at least without further configuration, it is possible to have style and theme attributes in XML not placed in the appropriate folder, like referring to "Holo" elements in the default resource folder when "whateversuitsyou" is smaller than 11 aka Honeycomb.
It seems apps will not crash if they encounter unknown XML style attributes. LogCat will show an error, like "Style contains key with bad entry".
Not sure whether the whole style is checked upon app startup; if so, it is certainly possible to run the app once on every API version to check for any problems. However, that's not exactly desirable. Besides, styles and themes are not the only version specific resources.
Is there a way to make lint check the resources in general against minSdkVersion and API versio XY for folder *-vXY? Can someone shed some light on this?
Luckily, with the current (updated) configuration, this has become a non-issue, because the development framework handles the situation just the way it should.
Example:
project.properties:
target=android-11
AndroidManifest.xml:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
You can now use API 8 XML style and theme attributes everywhere and API 11 XML style and theme attributes in -v11 subfolders.
Works with Eclipse Juno Service Release 1, Android SDK Tools 21.1 and Android SDK Platform-tools 16.0.1.

No resource ident ifier found for attribute 'widgetCategory' in package 'android'

widgetCategory was added in Android 4.2 SDK level 17. I decompiled an APK with apktool, added the widgetCategory attribute to a xml file, and recompiled.
The error is this:
No resource identifier found for attribute 'widgetCategory' in package 'android'
I have tried using the latest aapt and changing the sdk level in apktool.yml but neither solved the problem.
Is there anything I need to change to add support for Android 4.2 to apktool?
Set build target to API 17. In Eclipse you can achieve this by right clicking on the project and choose Properties. Then, under Android, select Android 4.2 as build target. It's also possible to just open the file project.properties and set target to android-17.
You do not have to change either minSdkVersion or targetSdkVersion in the Android Manifest.
I just ran into this issue myself. You need to update the MinSdkVersion of the App (in the manifest.xml) to 17.
If it uses a MinSdkVersion below 17, it will not recognize the widgetCategory resource.
Cheers!
All the answers are geared towards someone using Eclipse and Java when the OP said he's using apktool. Most likely the problem is apktool is using a framework SDK file below level 17. https://code.google.com/p/android-apktool/wiki/FrameworkFiles

Categories

Resources