簡體   English   中英

Android Studio Gradle項目同步 - 無法解析Espresso-Core和Appcompat

[英]Android Studio Gradle Project Sync - Failed To Resolve Espresso-Core and Appcompat

我正在關注https://developer.android.com/training/basics/firstapp/index.html上的“First App”教程。 但是,在創建默認的“空活動”項目並嘗試構建它時,我收到以下錯誤:

  • 錯誤:(23,24)無法解決:com.android.support.test:espresso-core:2.2.2
  • 錯誤:(26,13)無法解決:com.android.support:appcompat-v7:26.+

我的(默認/自動生成)build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.example.myfirstapp"
        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 {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

雖然我已經查看了幾個相關的Stack Overflow問題,但我還沒有找到一個有效的解決方案。 我正在使用Android Studio 2.3.3的全新默認安裝。

您應該檢查您的repository包含新的Google maven repo。
就像是:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

有關詳細信息,請參閱文檔

使用compile 'com.android.support:appcompat-v7:26.0.0-alpha1'

修改依賴性

compile 'com.android.support:appcompat-v7:25.3.1'

使用+可能會導致構建不穩定。

轉到SDK Manager並下載/更新所有必需的工具和平台。 這應該可以解決錯誤。

新的gradle 4.1有一些變化

而不是編譯我們應該在build.gradle文件中使用實現

*implementation 'com.android.support:appcompat-v7:26.0.0'*

gradle類路徑是

*classpath 'com.android.tools.build:gradle:3.0.0-alpha8'*

謝謝你的時間,我已經解決了這個問題!

雖然我不確定是什么導致它,但完全刪除並重新安裝Android Studio和Java SDK已經使錯誤消失了。 我相信它可能與我很久以前安裝的一些安卓軟件相沖突!

再次感謝您的建議,Oli

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM