Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build.gradle warning 'avoid using + in version numbers'

This is my build.gradle app-level file.

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 highlights the line

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

with the message

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

This line is auto-generated by Android Studio. Why this warning message? What I need to write to solve the warning ?

like image 498
F.M. Avatar asked Oct 17 '17 15:10

F.M.


People also ask

How do you check what version of Gradle is being used?

In Android Studio, go to File > Project Structure. Then select the "project" tab on the left. Your Gradle version will be displayed here.


2 Answers

Someday, someone else may do a git pull on your code and then try build an apk. This apk may have different behavior or even get a build error or run time error, because the dependencies version can be different than the dependencies used when you created this code.

You should use an explicit dependency version. I suggest use the newest version. You can search on bintray jcenter to see the newest version. If you are using Android Studio, File -> Project Structure -> Modules -> (your module, app usually) -> Dependencies -> Add library dependency (click the + sign) will give you the newest version, even add library automatically.

like image 200
BaiJiFeiLong Avatar answered Sep 29 '22 23:09

BaiJiFeiLong


You can use something like

compile 'com.android.support:appcompat-v7:26.1.0'
like image 42
Amit Barjatya Avatar answered Sep 29 '22 22:09

Amit Barjatya