由于gradle错误,无法启动新项目 [英] Can't start a new project because of gradle error

查看:656
本文介绍了由于gradle错误,无法启动新项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我照例创建了一个新项目,并在gradle运行后出现此错误:
`错误:执行任务失败':app:preDebugAndroidTestBuild'。



< blockquote>

与项目':app'中的依赖'com.android.support:support-annotations'冲突。应用程序(26.1.0)和测试应用程序(27.1.1)的已解决版本不同。请参阅 https://d.android.com/r/tools


这是我的新项目gradle:

p>

  apply plugin:'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationIdcom.example.elili.deltacalculator
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName1.0
testInstrumentationRunner android.support.test.runner.AndroidJUnitRunner

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


依赖关系{
implementation fileTree(dir:'libs',include:['* .jar '])
implementation'com.android.support:appcompat-v 7: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'
解决方案



如果您不打算实施测试代码,请从您的应用中删除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'

这篇关于由于gradle错误,无法启动新项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆