android - 更新后在 Android 2.3 中构建项目的问题。 'all com.android.support libraries must use the exact same version'

标签 android android-studio gradle android-support-library

更新后,我已将我的 AndroidStudio 从 2.2.3 更新到 2.3,我的项目开始出现一些构建冲突:所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 25.2.0、25.0.2

应用程序模块 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
def AAVersion = '4.2.0'
apply plugin: 'io.fabric'


apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
    }
}
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        // The Fabric Gradle plugin uses an open ended version to react
        // quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
repositories {
    maven {
        url "https://jitpack.io"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
    maven {
        url 'https://zendesk.artifactoryonline.com/zendesk/repo'
    }
    maven {
        url 'https://maven.fabric.io/public'
    }
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "amaro.amaroandroid"
        minSdkVersion 21
        targetSdkVersion 25
        renderscriptTargetApi 25
        renderscriptSupportModeEnabled true
        versionCode 6
        versionName "1.01"
        //Instrumentation Test Runner
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        // Enabling multidex support.
        multiDexEnabled true
        manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                onesignal_app_id               : "32551ffc-b35d-482f-81c7-2c4206811814",
                                onesignal_google_project_number: "867653264688"]
        vectorDrawables.useSupportLibrary = true
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

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

    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "2g"
    }

}

afterEvaluate {
    tasks.matching {
        it.name.startsWith('dex')
    }.each { dx ->
        if (dx.additionalParameters == null) {
            dx.additionalParameters = []
        }
        dx.additionalParameters += '--multi-dex'
        dx.additionalParameters += "--main-dex-list=$projectDir/multidex.keep".toString()
    }
}
allprojects {
    repositories {
        mavenCentral()
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':api')

    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"

    compile group: 'com.zopim.android', name: 'sdk', version: '1.3.2.1'
    // Required for geotagging
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
        transitive = true;
    }
    compile 'com.google.maps.android:android-maps-utils:0.4.+'
    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support:cardview-v7:25.2.0'
    compile 'org.jsoup:jsoup:1.10.2'
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.5'
    compile 'com.mikepenz:iconics-core:2.6.6@aar'
    compile 'com.mikepenz:google-material-typeface:2.2.0.1.original@aar'
    compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.1@aar'
    compile 'com.mikepenz:fontawesome-typeface:4.6.0.1@aar'
    compile 'com.mikepenz:octicons-typeface:3.2.0.1@aar'
    compile 'com.mikepenz:meteocons-typeface:1.1.0.1@aar'
    compile 'com.mikepenz:community-material-typeface:1.5.54.1@aar'
    compile 'com.mikepenz:weather-icons-typeface:2.0.10.1@aar'
    compile 'com.mikepenz:typeicons-typeface:2.0.7.1@aar'
    compile 'com.mikepenz:entypo-typeface:1.0.0.1@aar'
    compile 'com.mikepenz:devicon-typeface:2.0.0.1@aar'
    compile 'com.mikepenz:foundation-icons-typeface:3.0.0.1@aar'
    compile 'com.mikepenz:ionicons-typeface:2.0.1.1@aar'
    compile 'com.github.Yalantis:Context-Menu.Android:v1.0.4'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
    compile 'com.rengwuxian.materialedittext:library:2.1.4'
    compile 'com.github.medyo:fancybuttons:1.8.3'
    compile 'com.yarolegovich:lovely-dialog:1.0.4'
    compile 'com.wang.avi:library:1.0.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.traex.rippleeffect:library:1.3'
    compile 'com.balysv:material-ripple:1.0.2'
    compile 'com.mikepenz:actionitembadge:3.2.5@aar'
    compile 'com.github.linger1216:labelview:v1.1.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.onesignal:OneSignal:3.+@aar'
    compile 'com.google.android.gms:play-services-places:10.2.0'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.google.android.gms:play-services-analytics:10.2.0'
    compile 'com.android.support:support-v4:25.2.0'
    compile 'com.github.rahatarmanahmed:circularprogressview:2.5.0'
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.+'
    androidTestCompile 'com.android.support:support-annotations:25.2.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-idling-resource:2.2.2'
    androidTestCompile 'org.mockito:mockito-core:1.+'
    androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
}

项目 build.gradle
   // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'com.google.gms:google-services:3.0.0'
        // replace with the current version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'me.tatarka:gradle-retrolambda:3.2.4'
        classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}

allprojects {
    repositories {
        jcenter()
        jcenter()
        mavenCentral()
        maven { url 'http://repo.spring.io/milestone' }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
    configurations.all {
        resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
        resolutionStrategy {
            force 'com.android.support:support-annotations:25.2.0'
        }
    }
}

def getDate() {
    def date = new Date()
    def formattedDate = date.format('yyyyMMdd-HHmm')
    return formattedDate
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

api 模块 build.gradle
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'
def AAVersion = '4.2.0'

apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
    }
}
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 25
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "SHARE_URL", System.getenv("RSAPIURL") ? "\"" + System.getenv("RSAPIURL") + "\"" : "\"https://amaro.com\""
            buildConfigField "String", "API_URL", System.getenv("RSAPIURL") ? "\"" + System.getenv("RSAPIURL") + "\"" : "\"https://amaro.com/shop/api/\""
            buildConfigField "String", "DEV_API_URL", System.getenv("RSAPIURL") ? "\"" + System.getenv("RSAPIURL") + "\"" : "\"https://amaro.com/shop/api/\""//https://amaro.com/shop/api/
            buildConfigField "String", "SESSION", "\"_aecp\""//_aecp
            buildConfigField "String", "AUTHENTICATION", "\"_aecp_user\""//_aecp_user
        }
        debug {
            minifyEnabled false
            debuggable true
            buildConfigField "String", "SHARE_URL", System.getenv("RSAPIURL") ? "\"" + System.getenv("RSAPIURL") + "\"" : "\"https://amaro.com\""
            buildConfigField "String", "API_URL", System.getenv("RSAPIURL") ? "\"" + System.getenv("RSAPIURL") + "\"" : "\"https://amaro.com/shop/api/\""
            buildConfigField "String", "DEV_API_URL", System.getenv("RSAPIURL") ? "\"" + System.getenv("RSAPIURL") + "\"" : "\"http://dev.amaro.com/shop/api/\""//
            buildConfigField "String", "SESSION", "\"_aecp_dev\""//_aecp_dev
            buildConfigField "String", "AUTHENTICATION", "\"_aecp_dev_user\""//_aecp_dev_user
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile "org.projectlombok:lombok:1.16.6"

    apt "org.androidannotations:rest-spring:$AAVersion"
    compile "org.androidannotations:rest-spring-api:$AAVersion"
    compile 'org.springframework.android:spring-android-rest-template:2.0.0.M3'

    compile "commons-lang:commons-lang:2.6"

    compile "com.j256.ormlite:ormlite-jdbc:4.48"
    compile "com.j256.ormlite:ormlite-android:4.48"
    compile "org.jdeferred:jdeferred-core:1.2.2"
    compile "org.javamoney:moneta-bp:1.0"

    compile 'com.fasterxml.jackson.core:jackson-core:2.1.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.1.0'
    compile 'com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.1.0'

    compile 'com.squareup:otto:1.3.8'
}

最佳答案

解决了!

在你的根 build.gradle 中,你应该有

ext {
supportlib_version = '25.2.0'
...
}


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

在你的模块 build.gradle 必须有
dependencies {
    compile "com.android.support:appcompat-v7:25.2.0"
    compile "com.android.support:recyclerview-v7:25.2.0"
    ...
}

关于android - 更新后在 Android 2.3 中构建项目的问题。 'all com.android.support libraries must use the exact same version',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42658286/

相关文章:

android - 直接下载安装一个android apk

android - 某些设备中的 PlayStore 应用程序仍显示旧版本,而新版本已上线并可在 Play 商店中使用

java - Gradle 和 Spring 的几个模块

java - 由 : java. lang.NullPointerException 引起:尝试在空对象引用上调用接口(interface)方法

android - 无法调试 Android 应用程序

java - 使用 Android Studio 单击“构建 APK”时出错

android-studio - 在多应用程序项目中安装依赖的应用程序

gradle - 无法使Gradle签名插件与子项目一起使用

android - 如何创建具有 root 访问权限的 Android 应用程序?

android - Checkstyle 自定义检查与 gradle (android studio)