android - build.gradle 警告 'avoid using + in version numbers'

标签 android android-studio gradle libraries android-appcompat

这是我的 build.gradle 应用级文件。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "it.myco.app.myproj"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

Android Studio 高亮行

compile 'com.android.support:appcompat-v7:26.+'

与消息

avoid using + in version numbers can lead to unpredictable and unrepeatable builds

此行由 Android Studio 自动生成。为什么出现此警告消息?我需要写什么来解决警告?

最佳答案

有一天,其他人可能会对您的代码执行 git pull,然后尝试构建 apk。此 apk 可能具有不同的行为,甚至出现构建错误或运行时错误,因为依赖项版本可能与您创建此代码时使用的依赖项版本不同。

您应该使用显式依赖版本。我建议使用最新版本。您可以搜索 bintray jcenter查看最新版本。如果您使用的是 Android Studio,File -> Project Structure -> Modules -> (your module, app usually) -> Dependencies -> Add library dependency (click the + sign) 会给你最新的版本,甚至自动添加库。

关于android - build.gradle 警告 'avoid using + in version numbers',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46793888/

相关文章:

android - Jenkins Lint 插件没有获取结果

android - 有没有办法将MySql数据库连接到eclipse?

android - 搜索栏未到达末尾

Android 资源阿拉伯语本地化

java - Android Studio 使用模块

android - 使用实验性 gradle 插件时,模块应用程序依赖项会导致 "error: package x does not exist"

java - Android:倒数计时器,例如10:00 到 00:00?使用 OnclickListener 到 TextView?

java - 使用没有缓冲阅读器的扫描仪从 Assets 中的文本文件中读取双倍

java - 导入 android.util.LOG;未使用的导入语句android-studio

java - 带有 Spring Boot 2 错误的 Kotlin JPA 插件