三木社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 950|回复: 0
打印 上一主题 下一主题

[开发工具] Android Studio阿里镜像配置

[复制链接]

1657

主题

1684

帖子

5684

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5684
跳转到指定楼层
楼主
发表于 2019-5-15 09:14:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如果你之前设置过 Android Studio 的 HTTP Proxy,然后又取消了代理设置,那么很有可能 Andoid Studio gradle 再次编译时仍然会走代理设置,造成依赖资源一直下载失败。
分为两种:
  • 单独工程配置镜像
  • 整体工程配置
单独工程配置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 库地址:


  1. // Top-level build file where you can add configuration options common to all sub-projects/modules.

  2. buildscript {
  3.     repositories {

  4.         // 添加阿里云 maven 地址         
  5.         maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  6.         maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }

  7.         // jcenter()
  8.         google()
  9.     }
  10.     dependencies {
  11.         classpath 'com.android.tools.build:gradle:3.2.1'
  12.         // NOTE: Do not place your application dependencies here; they belong
  13.         // in the individual module build.gradle files
  14.     }
  15. }

  16. allprojects {
  17.     repositories {

  18.         // 添加阿里云 maven 地址         
  19.         maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  20.         maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }

  21.         // jcenter()
  22.         google()
  23.     }
  24. }

  25. task clean(type: Delete) {
  26.     delete rootProject.buildDir
  27. }
复制代码
重新 SYNC 项目,编译时的资源下载一般就会如丝般顺滑了。
全局配置在C:\Users\Administrator.gradle中新建init.gradle,并输入如下内容:
  1. allprojects{
  2.     repositories {
  3.         def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
  4.         def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  5.         all { ArtifactRepository repo ->
  6.             if(repo instanceof MavenArtifactRepository){
  7.                 def url = repo.url.toString()
  8.                 if (url.startsWith('https://repo1.maven.org/maven2')) {
  9.                     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
  10.                     remove repo
  11.                 }
  12.                 if (url.startsWith('https://jcenter.bintray.com/')) {
  13.                     project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
  14.                     remove repo
  15.                 }
  16.             }
  17.         }
  18.         maven {
  19.             url ALIYUN_REPOSITORY_URL
  20.             url ALIYUN_JCENTER_URL
  21.         }
  22.     }
  23. }

复制代码
重启Android Studio 并clean rebuild 即可
转载地址:
https://www.jianshu.com/p/b038bd95444b

回复

使用道具 举报

Archiver|手机版|小黑屋|三木电子社区 ( 辽ICP备11000133号-4 )

辽公网安备 21021702000620号

GMT+8, 2025-12-31 00:44 , Processed in 0.029423 second(s), 22 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表