18

Reading the Compatibility section of Android L Developer Preview (http://developer.android.com/preview/material/compatibility.html) I've seen that i can create an APP using L-sdk and also be able to run it on older sdk (like KitKat).

I've created a new project using Android L sdk and configured "build.gradle" as said in this post: Android Studio : Failure [INSTALL_FAILED_OLDER_SDK].

I've tried both the configurations:

  • the one proposed in question that gives me this error:

    pkg: /data/local/tmp/com.example.{my user name}.materialapp Failure [INSTALL_FAILED_OLDER_SDK]

  • and the one proposed in answer that gives me error on

    <style name="AppTheme" parent="android:Theme.Material.Light"></style>

I've searched on others question on StackOverflow but I can't find no solutions.

SOLUTION: Android L preview material style can be used only on devices that run Android L. The "compatibility" is only a preview and it's not enabled.

Community
  • 1
  • 1
Luca
  • 823
  • 4
  • 11
  • 31

2 Answers2

11

You have to create 2 different styles.xml files with the same name that you will put in different folders.

The first, will go here:

res/styles.xml

and will look NOT have a reference to the Material theme (use the Holo theme):

so would have something like this:

<style name="AppTheme" parent="android:Theme.Holo.Light"></style>

The second will go here:

res/values-v21/styles.xml

and WILL contain the reference to the new Material theme, and would have:

<style name="AppTheme" parent="android:Theme.Material.Light"></style>

The Android framework will automatically use the correct one depending on which API the device supports (so on API 21 devices it will use Material, and on all other devices, it will use whatever else you define).

Booger
  • 18,579
  • 7
  • 55
  • 72
  • 1
    I already have 2 different styles.xml: one in values and one in values-v21. But if i try to deploy the app on my Nexus 5 (with 4.4.4) it crashes on android:Theme.Material.Light – Luca Jul 08 '14 at 15:00
  • Are they both named "AppTheme" no typos or different parents? – Booger Jul 08 '14 at 16:41
  • 1
    No typos. Same parents. – Luca Jul 08 '14 at 18:38
  • I've just tried using "build.gradle" like the one in Vova.K comment in this post [link](http://stackoverflow.com/questions/24465289/android-studio-failure-install-failed-older-sdk) but it gives error on `android:Theme.Material.Light`, saying **Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'.** – Luca Jul 08 '14 at 18:52
  • 1
    Maybe you don't have the proper support library linked? You will need to ensure you have the preview version (L). I bet that is it (if I remember correctly, you also need to opt-in to the preview group somehow). – Booger Jul 08 '14 at 19:15
  • I have installed every sdk from release 15 to now. If i use **minSdkVersion 17** and try to run it on my Nexus 5 (sdk 19) it should go... but it says (again) **Failure [INSTALL_FAILED_OLDER_SDK]**. Already tryied to sync project with gradle files. I can't get over it.... – Luca Jul 08 '14 at 19:18
  • @Luca Try it out from Eclipse, and check if your target in Manifest is set to be Android L. Here is a useful link: http://www.reddit.com/r/androiddev/comments/297xli/howto_use_the_v21_support_libs_on_older_versions/ – milosmns Aug 25 '14 at 14:55
  • @milosmns, could you please edit your comment? The link you gave is useful, and I got [RecyclerView](https://developer.android.com/preview/material/ui-widgets.html#recyclerview) to work. But the author suggests using Android Studio rather than Eclipse. – Maksim Dmitriev Sep 05 '14 at 14:27
  • @MaksimDmitriev Not sure what do you want me to edit. My suggestion is to still use Eclipse as Android Studio is in beta, and takes a lot of unnecessary work to port already working complex projects (if that was what you were referring to). Link was just something I found on this subject, thought that it could help – milosmns Sep 05 '14 at 15:52
1

This has changed since the original answer, as Google released better support for Material design in the AppCompat libraries (which support mostly all versions of Android).

At this point, you should be using these libraries for all development, then you will be able to support Material design related features in all your apps.

Here is how to set it up: https://developer.android.com/topic/libraries/support-library/setup.html

Booger
  • 18,579
  • 7
  • 55
  • 72