简体   繁体   中英

Support library version

I try to inject support libraries into my Android Studio project.

If I try anything lower than 20 it says: library should not use a lower version then targetSdk version.

If I use compile 'com.android.support:support-v4:20' I get: Failed to find: com.android.support:support-v4:20

If I use compile 'com.android.support:support-v7:20.0.+' I get: Avoid using + in version numbers, can lead to unpredictable and unrepeatable builds.

So the simple question is: where can I find up-to-date, ready to use, version numbers that Do work?

If I try anything lower than 20 it says: library should not use a lower version then targetSdk version.

That is because you set your targetSdkVersion to something higher than 19. If you did so intentionally, fine. If you did not do so intentionally, consider dropping it back to 19 for now, and use compile 'com.android.support:support-v4:19.1.0' (if you are using the backport of fragments) or compile 'com.android.support:support-v13:19.1.0' (if you are not using the backport of fragments).

If I use compile 'com.android.support:support-v4:20' I get: Failed to find: com.android.support:support-v4:20

That is because the Android Support package uses XYZ semantic versioning, as do most artifacts in repositories. 20 does not match the XYZ pattern.

If I use compile 'com.android.support:support-v7:20.0.+' I get: Avoid using + in version numbers, can lead to unpredictable and unrepeatable builds.

That is merely a warning. If you are using version control for your project files, and you feel that it is important to be able to check out some earlier version of your code and be able to reproduce that build, then using the + notation is not a good idea. OTOH, if being able to reproduce historical builds is not essential, using the + wildcard, as you are doing, ensures that you get updates automatically. Having the + in the third position (Z in XYZ) means that you will automatically get patchlevel updates.

where can I find up-to-date, ready to use, version numbers that Do work?

On your hard drive, in $ANDROID_SDK/opt/extras/android/m2repository/com/android/support/$LIBRARY/ , where $ANDROID_SDK is wherever you installed the Android SDK and $LIBRARY is whichever Android Support package library you are interested in (eg, support-v13 ).

To see the current Android Support Library revision number ...

  • Android Studio > Tools > Android > SDK Manager ...
  • Extras > Android Support Library: See the Rev. number eg (21.0.3).

For a quick insertion of the right revision number when in your gradle file you currently have something like 'com.android.support:appcompat-v7:21.0.+' with the 'Avoid using + in version numbers ...' warning, use the relevant IntelliJ Inspection ...

  • Place your cursor over 'com.android.support:appcompat-v7:21.0.+' (anywhere in the colored section of the warning).
  • Alt + Enter > "Replace with specific version".

There are plans to include the latest specific version number in the warning. See Issue 78737: Have the "Avoid using + in version numbers" gradle library warning suggest the version currently in use.

你可以在这里获得support-v4的版本列表:\\ sdk \\ extras \\ android \\ m2repository \\ com \\ android \\ support \\ support-v4

You can see the versions at Google's Maven Repository . Just find the item entry com.android.support and click the plus to expand it. Scroll down and click on any artifact such as support-v13 and you'll see folders named after the version number.

Google的Maven资源库的屏幕截图

This will work:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.myApp"
        minSdkVersion 19
        targetSdkVersion 20
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:20.0.0')
}

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