Android Studio下载依赖慢,使用国内阿里云镜像搞定

首先百度 “Android Studio 依赖国内镜像”

好些文章都是在介绍这个方式,我试验了一下,行不通,所以代理这种就放弃了。

后来找到了这篇文章Android Studio配置阿里云镜像地址,加速依赖资源下载,感觉有希望。

于是用里面的链接http://maven.aliyun.com/nexus/content/groups/public 访问了一下,如下:

阿里云镜像

最后访问到了阿里云的镜像。参考里面的说明,我的文件如下:这个文件一般在C:\Users\你的用户名\.gradle   下。

文件内容,用了阿里的最新地址,新建一个init.gradle 文件,并把下面的内容复制粘贴进去

allprojects{
    repositories {
        def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central'
        def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                    remove repo
                }
            }
        }
        maven {
            url ALIYUN_REPOSITORY_URL
            url ALIYUN_JCENTER_URL
        }
    }


    buildscript{
        repositories {
        def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central'
        def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'
            all { ArtifactRepository repo ->
                if(repo instanceof MavenArtifactRepository){
                    def url = repo.url.toString()
                    if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {
                        project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                        remove repo
                    }
                    if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {
                        project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                        remove repo
                    }
                }
            }
            maven {
                url ALIYUN_REPOSITORY_URL
                url ALIYUN_JCENTER_URL
            }
        }
    }
}

以为大功告成了,结果还是遇到了几个问题。

1、需要把gradle中的也进行替换,如下截图:

2、出现类似 Could not find com.github.chrisbanes:PhotoView:1.2.6 的问题

关于此库的介绍https://cloud.tencent.com/developer/article/1330894 原来它是来源于

所以,试着增加为,结果是可以了。

3、最怪异的问题,一开始使用“仓库服务”老是出现Connection refused。确定没有使用proxy ,Android Studio重启了也还是不行。

最终,找到了如下文件,把这四行删除,试一下就行了,感觉是Android Studio的bug。

通过此问题,发现一个简单的道理,像Android Studio也是去操作电脑文件中的配置文件,也存在操作不成功的问题。

### OmegaConf 配置管理简介 OmegaConf 是一个强大的 Python 库,用于处理复杂的配置文件。它支持多种数据结构(如字典、列表)以及 YAML 文件的解析和操作。以下是有关如何使用 OmegaConf 的详细介绍。 #### 创建配置对象 可以通过 `OmegaConf.create` 方法创建一个新的配置对象。该方法可以接受字典、YAML 字符串或其他兼容的数据结构作为输入[^1]。 ```python import omegaconf from omegaconf import OmegaConf config_dict = {"database": {"host": "localhost", "port": 6379}} config = OmegaConf.create(config_dict) print(OmegaConf.to_yaml(config)) # 将配置转换为 YAML 格式的字符串 ``` #### 加载外部 YAML 文件 如果需要加载外部 YAML 文件,可使用 `OmegaConf.load` 方法。这使得程序能够轻松读取并应用存储在磁盘上的配置文件。 ```python yaml_file_path = "./example_config.yaml" file_conf = OmegaConf.load(yaml_file_path) # 打印加载后的配置内容 print(file_conf.database.host) # 输出 'localhost' ``` #### 合并多个配置源 当存在多个配置来源时(例如默认设置与命令行参数),可以使用 `OmegaConf.merge` 来无缝合并它们。此功能允许开发者优先级较高的配置覆盖较低级别的配置项。 ```python default_configs = OmegaConf.create({"model": {"type": "resnet50"}}) cli_args = OmegaConf.from_dotlist(["model.type=vgg16"]) merged_config = OmegaConf.merge(default_configs, cli_args) assert merged_config.model.type == "vgg16" # 命令行参数成功覆盖默认值 ``` #### 动态更新配置 除了静态定义外,还可以通过访问器动态修改现有配置中的字段。这种灵活性非常适合运行时调整某些超参数或环境变量。 ```python dynamic_update = file_conf.copy() dynamic_update.database.port = 8080 print(dynamic_update.database.port) # 输出新的端口号 8080 ``` #### 错误处理机制 为了防止非法赋值破坏整个系统的稳定性,OmegaConf 提供了严格的模式控制选项。启用严格模式后,任何未声明过的键都将引发异常提示用户修正错误。 ```python strict_mode_enabled = file_conf.copy() strict_mode_enabled.set_struct(True) # 开启只读保护状态 try: strict_mode_enabled.new_field = True # 此处会抛出 AttributeError 异常 except AttributeError as e: print(f"Catch expected error: {e}") ``` --- ### 总结 以上展示了 OmegaConf 在不同场景下的典型用法,包括但不限于初始化配置实例、加载外部资源、融合多层设定逻辑以及实施安全防护措施等方面的功能特性。希望这些例子能帮助快速掌握其核心概念和技术要点!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值