Android 默認的gradle地址 構建失敗,如果是網絡問題 可以使用 Android阿里鏡像地址構建

構建方法很簡單  替換google 的meaven  爲阿里的。

1.刪除 Android Studio 的代理設置

首先你需要確認你已經在 Settings -> Appearance&Behavior -> System Settings -> HTTP Proxy 中選中了 No Proxy。

然後找到項目根目錄下的 gradle.properties 文件,打開查看該文件中是否有關於 proxy 設置(代理的地址和端口)的相關語句,刪除這些內容,讓該文件看起來大致是這個樣子(如果你沒有添加其他設置的話):

最後,你需要找到你的另一個 gradle.properties 文件:C:\Users\Administrator.gradle\gradle.properties:

打開該文件,和上面的操作一樣,刪除與 proxy 設置相關的語句,讓該文件的內容看起來大致是這樣(如果你沒有添加其他設置的話):

2.讓項目通過阿里雲 maven jcenter 下載依賴資源

打開項目根目錄下的 build.gradle(Project:項目名稱一級的gradle),如下所示添加阿里 maven 庫地址:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
 
buildscript {
    repositories {
 
        // 添加阿里雲 maven 地址         
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
 
        // jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
 
allprojects {
    repositories {
 
        // 添加阿里雲 maven 地址         
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
 
        // jcenter()
        google()
    }
}
 
task clean(type: Delete) {
    delete rootProject.buildDir
}

查詢構建 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章