build.gradle警告'避免在版本号中使用+'

Fed*_*dro 5 android android-appcompat gradle libraries android-studio

这是我的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'
}
Run Code Online (Sandbox Code Playgroud)

Android Studio突出显示该行

compile 'com.android.support:appcompat-v7:26.+'
Run Code Online (Sandbox Code Playgroud)

随着消息

避免在版本号中使用+会导致不可预测和不可重复的构建

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

Bai*_*ong 6

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

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