Android Studio3.0 創(chuàng)建項(xiàng)目報錯Error:Execution failed for task ':app:preDebugAndroidTestBuild'

報錯信息:

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.

> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See [https://d.android.com/r/tools/test-apk-dependency-conflicts.html](https://d.android.com/r/tools/test-apk-dependency-conflicts.html) for details. Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar]

報錯內(nèi)容提示版本沖突:
應(yīng)用程序版本和測試應(yīng)用程序版本不一致沖突:

解決方案
參見stackoverflow:

1.在dependencies中添加代碼
compile 'com.android.support:support-annotations:27.1.1'

例如:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-annotations:27.1.1'    
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
  1. 按照官方文檔操作:
    官方文檔案例
    我的項(xiàng)目中是這么用的
    在頂層gradle文件中加入ext代碼塊
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

// This block encapsulates custom properties and makes them available to all
// modules in the project.
ext {
    // The following are only a few examples of the types of properties you can define.
    compileSdkVersion = 26
    buildToolsVersion = "27.0.3"

    // You can also use this to specify versions for dependencies. Having consistent
    // versions between modules can avoid behavior conflicts.
    supportLibVersion = "27.1.1"
}

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

然后在模塊級中的gradle文件中使用 也就是app/build.gradle

apply plugin: 'com.android.application'

android {

    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.chinalife.mcp.chinalife"
        minSdkVersion 15
        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 {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,094評論 25 709
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評論 19 139
  • 1,感恩早上,做了一個非常棒的教練,把PCC標(biāo)識用得非常流動,覺察到無意識的思維模式,因?yàn)楹昧?xí)慣有意識形成。(意志...
    monkey立敏閱讀 251評論 0 0
  • 文|VV行進(jìn)中的鯉魚 1988?你還記得1988年有過怎樣的故事?這是一個暴露年齡的問題,剛剛敲響的新年鐘聲,已將...
    VV行進(jìn)中的鯉魚閱讀 674評論 2 3
  • 老實(shí)講,昨天早上刷到這條新聞—— Sir就預(yù)感···要方。 流量明星稱霸電影節(jié),見得還少嗎? 左起,2014年“好...
    Sir電影閱讀 2,381評論 9 35

友情鏈接更多精彩內(nèi)容