且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

由于gradle错误,无法启动新项目

更新时间:2022-10-14 21:42:17



如果您不打算实施测试代码,请从您的应用中删除junit。

  apply plugin:'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationIdcom.example.elili.deltacalculator
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'




依赖关系{
implementation fileTree(dir:'libs',include:['* .jar'])
实现'com.android.support:appcompat-v7:26.1.0'
implementation'com.android.support.constraint:constraint-layout:1.1.0'


I created a new project as usual andafter the gradle running I get this error: `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 for details.`

This is my fresh project gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.elili.deltacalculator"
    minSdkVersion 18
    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:26.1.0'
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'

I have zero ideas on how to fix it...

If you are not going to implement testing code, then remove junit from your app. You can replace your gradle by below.

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.elili.deltacalculator"
    minSdkVersion 18
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
}
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'