依赖问题

时间:2017-10-15 17:03:19

标签: android android-preferences gradle-dependencies

我想创建很酷的偏好活动。所以我从github中选择一个多数库(假设这个:https://github.com/codevscolor/MaterialPreference) 但是当我将依赖写入build.gradle时,我发出了关于

的警告
  

“混合库版本(找到版本25.3.1。和23.4.0。)全部   库必须具有完全相同的版本规范“

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:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    //it's dependency for new great library
    compile 'com.codevscolor.materialpreference:mp:0.2.1'
}

有没有办法避免这种错误?

完整的build.gradle在这里:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.parkfinder"
        minSdkVersion 23
        targetSdkVersion 25
        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:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
    compile 'de.hdodenhof:circleimageview:1.3.0'
}

2 个答案:

答案 0 :(得分:1)

尝试添加

 compile 'com.android.support:preference-v7:25.3.1'

将build.gradle更新为

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:25.3.1'
compile 'com.android.support:preference-v7:25.3.1'

compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
testCompile 'junit:junit:4.12'
compile 'de.hdodenhof:circleimageview:1.3.0'
//it's dependency for new great library
compile 'com.codevscolor.materialpreference:mp:0.2.1'
}

答案 1 :(得分:0)

这是因为库com.codevscolor.materialpreference:mp:0.2.1正在使用支持库的版本25.4.0。 您必须将支持库从25.3.1升级到25.4.0才能使用该依赖项。

所以,在你的情况下:

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'
    })
    // Upgrade the support dependencies to 25.4.0
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:support-v4:25.4.0'
    compile 'com.android.support:design:25.4.0'
    // Move it from alpha to the latest stable version.
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    //it's dependency for new great library
    compile 'com.codevscolor.materialpreference:mp:0.2.1'
}