AndroidStudio升級報錯Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve c

lvxiangan發表於2018-12-06

近日升級AS到3.2.1版本,新建工程時報錯:


 

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve junit:junit:4.12.
Open File
Show Details
 


錯誤原因:專案預設配置了gradle 4.6版本,映象伺服器錯誤(mirrors.neusoft.edu.cn 沒有提供下載服務)導致無法下載gradle-4.6-all.zip,無法完成編譯。

 

解決方法1:降低gradle版本

  • 開啟 gradle/wrapper/gradle-wrapper.properties,修改gradle版本為本地已下載版本。如gradle-4.4-all.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

記得同時修改build.gradle內容:3.1.0

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'    
}

解決方法2:更新到最新版本

  • 不使用映象地址下載gradle-4.6-all.zip,因為映象地址連線失敗,所以把它拿掉。
    找到
    /Users/lvxiangan/.gradle資料夾,開啟gradle.properties

     

    ## For more details on how to configure your build environment visit
    # http://www.gradle.org/docs/current/userguide/build_environment.html
    #
    # Specifies the JVM arguments used for the daemon process.
    # The setting is particularly useful for tweaking memory settings.
    # Default value: -Xmx1024m -XX:MaxPermSize=256m
    # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    #
    # When configured, Gradle will run in incubating parallel mode.
    # This option should only be used with decoupled projects. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    # org.gradle.parallel=true
    #Thu Dec 06 23:52:05 CST 2018
    使用#號註釋掉以下4行
    systemProp.http.proxyHost=mirrors.neusoft.edu.cn
    systemProp.http.proxyPort=80
    systemProp.https.proxyHost=mirrors.neusoft.edu.cn
    systemProp.https.proxyPort=80

    或者刪除整個檔案。重啟AS,可以看到正在重新下載gradle-4.6-all.zip

     
  • 如果上一步下載很慢,可以通過網盤或迅雷下載到本地,從本地直接載入。

    下載好複製到 /Users/lvxiangan/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg 資料夾下,然後重啟AS。

    注意:bcst21l2brirad8k2ben1letg 資料夾名稱是由系統隨機產生,請不要嘗試修改它。

最後來一張成功編譯圖,晚安!

 

 

 

 

相關文章