简体   繁体   中英

How can I download an old version of the Android support library?

I'm targeting Android 19 (because that's what my phone is running). I want to add a notification with buttons; it seems the right approach is to use appcompat-v7.app.NotificationCompat.

However, when I add appcompat-v7 from the Android Support repository revision 22.2 (via a build.gradle dependency), it includes a file app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/res/values-v21/values-v21.xml that doesn't compile because it assumes the target is 21+.

I tried deleting that file, but it gets regenerated.

There doesn't seem to be a way to exclude a file from the build.

So, I need to get an older version of the support library or repository, that doesn't include 21 stuff.

I guess I could import all the sources directly (and leave out the v21 stuff), rather than thru the dependency? I'm not clear where to start with that. I can use the SDK manager to get older versions of the SDK, but it only offers the latest version of the support library.

In your gradle build file change the dependency to be the 19 version (the version of the library should match the sdk you are compiling with):

dependencies {
    compile 'com.android.support:appcompat-v7:19.1.+'
...
}

Edit: If v19 of the support lib doesn't have NotificationCompat, then you can't use that unless you compile against a later SDK. You can't include a support library with a higher version than your compiled SDK - that's the issue you are running into.

In this case change:

android {
    compileSdkVersion 22
    ...
}

and leave the dependency set to the 22 version of the appcompat support lib

to directly answer your question it's all that one line on gradle:

compile 'com.android.support:appcompat-v7:22.2.0'

That last part is the version you're getting. 22.2.0 on the example above.

and on this link you can check the revisions numbers: https://developer.android.com/tools/support-library/index.html#revisions

But you have a fundamentally wrong approach to your issue. You don't have to target the API for the device you have with you. You can easily and safely target the latest API, use the latest AppCompat features and bug fixes.

Lint will give you a warning every time you try to use a feature that is not from your minimumApi , regardless of the targetAPI

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM