首页 文章

Android依赖项对于编译和运行时具有不同的版本

提问于
浏览
57

将Android Studio从 Canary 3 更新为 Canary 4 后,在构建时抛出以下错误 .

Android依赖项'com.android.support:support-support-v4'具有不同版本的编译(25.2.0)和运行时(26.0.0-beta2)类路径 . 您应该通过DependencyResolution手动设置相同的版本 .

我在整个项目中运行了一个完整的搜索,版本 25.1.0 没有使用 .

App-build.gradle

android {
compileSdkVersion 26
buildToolsVersion '26.0.0'


defaultConfig {
    applicationId "com.xxx.xxxx"
    minSdkVersion 14
    targetSdkVersion
    versionCode 1
    versionName "1.0"
    multiDexEnabled true

}


buildTypes {
    debug {
        debuggable true
    }
    release {
        debuggable false
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    lintOptions {
        abortOnError false
    }

}}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation project(':core')
implementation com.google.android.gms:play-services-gcm:9.0.0'

implementation('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
    transitive = true
}
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.flurry.android:analytics:7.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
implementation 'com.jakewharton:butterknife:8.6.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

Library-build.gradle:

apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'

defaultConfig {
    minSdkVersion 14
    targetSdkVersion
    versionCode 1
    versionName "1.0"
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation files('libs/model.jar')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:percent:26.0.0-beta2'
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
implementation 'com.android.support:support-core-utils:26.0.0-beta2'

implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.picasso:picasso:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.2.0'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation 'com.google.code.gson:gson:2.2.4'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1'

}

Note: 项目在Canary 3建造得很好

11 回答

  • 0

    在您的buildscript(build.gradle root)中使用此代码:

    subprojects {
      project.configurations.all {
         resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                  && !details.requested.name.contains('multidex') ) {
               details.useVersion "version which should be used - in your case 26.0.0-beta2"
            }
         }
      }
    }
    
  • 1

    我有同样的错误,解决了我的问题是什么 . 在我的 library 而不是使用编译或实现我使用"api" . 所以最后我的依赖:

    dependencies {
    api fileTree(dir: 'libs', include: ['*.jar'])
    api files('libs/model.jar')
    testApi 'junit:junit:4.12'
    api 'com.android.support:percent:26.0.0-beta2'
    api 'com.android.support:appcompat-v7:26.0.0-beta2'
    api 'com.android.support:support-core-utils:26.0.0-beta2'
    
    api 'com.squareup.retrofit2:retrofit:2.0.2'
    api 'com.squareup.picasso:picasso:2.4.0'
    api 'com.squareup.retrofit2:converter-gson:2.0.2'
    api 'com.squareup.okhttp3:logging-interceptor:3.2.0'
    api 'uk.co.chrisjenx:calligraphy:2.2.0'
    api 'com.google.code.gson:gson:2.2.4'
    api 'com.android.support:design:26.0.0-beta2'
    api 'com.github.PhilJay:MPAndroidChart:v3.0.1'
    }
    

    你可以在这个链接中找到有关"api","implementation"的更多信息https://stackoverflow.com/a/44493379/3479489

  • 72

    通过为项目运行正确的 gradle -q dependencies 命令,您应该能够确切地看到奇怪版本中的哪个依赖项作为传递依赖项:

    https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

    一旦你追踪到它的内容,你可以在gradle文件中添加一个排除到特定的依赖项,例如:

    implementation("XXXXX") {
        exclude group: 'com.android.support', module: 'support-compat'
    }
    
  • 16

    经过很多时间并得到一位朋友的帮助,这位朋友比我更了解android:app / build.gradle

    android {
        compileSdkVersion 27
    
        // org.gradle.caching = true
    
        defaultConfig {
            applicationId "com.cryptoviewer"
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 196
            versionName "16.83"
            // ndk {
            //     abiFilters "armeabi-v7a", "x86"
            // }
        }
    

    和依赖

    dependencies {
        implementation project(':react-native-camera')
       //...
        implementation "com.android.support:appcompat-v7:26.1.0" // <= YOU CARE ABOUT THIS
        implementation "com.facebook.react:react-native:+"  // From node_modules
    }
    

    在build.gradle中

    allprojects {
       //...
        configurations.all {
            resolutionStrategy.force "com.android.support:support-v4:26.1.0"
        }
    

    在gradle.properties中

    android.useDeprecatedNdk=true
    android.enableAapt2=false
    org.gradle.jvmargs=-Xmx4608M
    
  • 11

    我的解决方案:在依赖项部分的app / src / build.gradle中添加以下行:

    implementation "com.android.support:appcompat-v7:27.1.0"
    

    或者:在我的情况下为27.1.1

  • 74

    我按照Eddi上面提到的那样解决了这个问题,

    resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "26.1.0"
                }
            }
    
  • 0

    我的答案是将此添加到我的 build.gradle 文件中:

    configurations.all {
      resolutionStrategy.eachDependency { details ->
          if (details.requested.group == 'com.android.support'
                  && !details.requested.name.contains('multidex') ) {
              details.useVersion "26.1.0"
          }
      }
    }
    

    就我而言,将决议策略包含在 configurations.all { .. } 块中是必要的 . 我将 configurations.all 块直接放入我的 app/build.gradle 文件中(即 configurations.all 未嵌套在其他任何内容中)

  • 4

    将我的冲突依赖项从实现切换到api就可以了 . 这是Mindorks解释差异的好文章 .

    https://medium.com/mindorks/implementation-vs-api-in-gradle-3-0-494c817a6fa

    编辑:

    这也是我的依赖性解决方案

    subprojects {
            project.configurations.all {
                resolutionStrategy.eachDependency { details ->
                    if (details.requested.group == 'com.android.support'
                            && !details.requested.name.contains('multidex')) {
                        details.useVersion "28.0.0"
                    }
                    if (details.requested.group == 'com.google.android.gms'
                            && details.requested.name.contains('play-services-base')) {
                        details.useVersion "15.0.1"
                    }
                    if (details.requested.group == 'com.google.android.gms'
                            && details.requested.name.contains('play-services-tasks')) {
                        details.useVersion "15.0.1"
                    }
                }
            }
        }
    
  • -6

    我评论出 //api 'com.google.android.gms:play-services-ads:15.0.1' 它在同步后对我有用

  • 3

    在您的库项目中看到 compileSdkVersiontargetSdkVersion 版本与您的应用程序相同

    android {
        compileSdkVersion 28
    
        defaultConfig {
            consumerProguardFiles 'proguard-rules.txt'
            minSdkVersion 14
            targetSdkVersion 28
        }
    }
    

    也使所有依赖关系达到同一级别

  • 1

    将硬编码版本替换为示例:

    implementation 'com.google.android.gms:play-services-base:+'
    implementation 'com.google.android.gms:play-services-maps:+'
    

相关问题