Android Studio解决无法添加远程依赖问题

Android Studio解决无法添加远程依赖问题

最近遇到Android Studio在打开一个环境版本不匹配的项目时sync fialed 不能下载依赖的问题,在引入远程依赖包的时候,会出现一个sync fialed的错误。

来看解决方案

  1. 先在setting里面;(顺便看一下防火墙,有没有拦截android studio)Android Studio解决无法添加远程依赖问题
  2. 然后在这个关掉离线;Android Studio解决无法添加远程依赖问题
  3. 在项目的gradle里面这样配置;Android Studio解决无法添加远程依赖问题
    最后,同步一***意观察界面下方gradle加载的依赖的方式,是https还是http,如果https下载不下来 就换http,一遍两遍解决问题;(jcenter {url “http://jcenter.bintray.com/”}是指定的地址http的, jcenter()是用动态默认的https,切换这个就好)

结论,就是遇到问题不要慌,仔细观察他哪里出现了问题,在想对策。

项目的build.gradle 代码片.

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter {
            url "http://jcenter.bintray.com/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

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

重要的事情说一说,好多人遇到了希望可以多试两边,不要心急。