阿里云maven仓库的使用 、 Could not download preference-1.1.1.aar

参考:

阿里云仓库文件

阿里云使用指南

Android studio 全局搜索 ArtifactRepositoryContainer 即可查看依赖的maven仓库详细地址:

String DEFAULT_MAVEN_CENTRAL_REPO_NAME = "MavenRepo";
String DEFAULT_MAVEN_LOCAL_REPO_NAME = "MavenLocal";
String MAVEN_CENTRAL_URL = "https://repo.maven.apache.org/maven2/";
String GOOGLE_URL = "https://dl.google.com/dl/android/maven2/";

打开Android studio 的 setting 找到如下位置,测试Google仓库地址的网络是否正常访问:

在这里插入图片描述

这里不可访问,提示如下:

在这里插入图片描述

我们可以换成阿里云仓库即可。


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

        maven{ url 'https://maven.aliyun.com/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
        maven{ url 'https://maven.aliyun.com/repository/public'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}

        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.2"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {

        maven{ url 'https://maven.aliyun.com/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
        maven{ url 'https://maven.aliyun.com/repository/public'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}

        google()
        mavenCentral()
//        jcenter() // Warning: this repository is going to shut down soon
    }
}

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

Unexpected tokens (use ‘;’ to separate expressions on the same line)

//Unexpected tokens (use ';' to separate expressions on the same line)
    //android studio-2024.1.1版本 新写法
    maven{ url=uri("https://maven.aliyun.com/repository/google")}
    maven{ url=uri("https://maven.aliyun.com/repository/gradle-plugin")}
    maven{ url=uri("https://maven.aliyun.com/repository/public")}
    maven{ url=uri("https://maven.aliyun.com/repository/jcenter")}

阿里云maven仓库

仓库名称阿里云仓库地址阿里云仓库地址(老版)源地址
centralhttps://maven.aliyun.com/repository/centralhttps://maven.aliyun.com/nexus/content/repositories/centralhttps://repo1.maven.org/maven2/
jcenterhttps://maven.aliyun.com/repository/jcenterhttps://maven.aliyun.com/nexus/content/repositories/jcenterhttp://jcenter.bintray.com/
publichttps://maven.aliyun.com/repository/publichttps://maven.aliyun.com/nexus/content/groups/publiccentral仓和jcenter仓的聚合仓
googlehttps://maven.aliyun.com/repository/googlehttps://maven.aliyun.com/nexus/content/repositories/googlehttps://maven.google.com/
gradle-pluginhttps://maven.aliyun.com/repository/gradle-pluginhttps://maven.aliyun.com/nexus/content/repositories/gradle-pluginhttps://plugins.gradle.org/m2/
springhttps://maven.aliyun.com/repository/springhttps://maven.aliyun.com/nexus/content/repositories/springhttp://repo.spring.io/libs-milestone/
spring-pluginhttps://maven.aliyun.com/repository/spring-pluginhttps://maven.aliyun.com/nexus/content/repositories/spring-pluginhttp://repo.spring.io/plugins-release/
grails-corehttps://maven.aliyun.com/repository/grails-corehttps://maven.aliyun.com/nexus/content/repositories/grails-corehttps://repo.grails.org/grails/core
apache snapshotshttps://maven.aliyun.com/repository/apache-snapshotshttps://maven.aliyun.com/nexus/content/repositories/apache-snapshotshttps://repository.apache.org/snapshots/

gradle 配置指南

在 build.gradle 文件中加入以下代码:

allprojects {
  repositories {
    maven {
      url 'https://maven.aliyun.com/repository/public/'
    }
    mavenLocal()
    mavenCentral()
  }
}

如果想使用其它代理仓,以使用spring仓为例,代码如下:

allProjects {
  repositories {
    maven {
      url 'https://maven.aliyun.com/repository/public/'
    }
    maven {
      url 'https://maven.aliyun.com/repository/spring/'
    }
    mavenLocal()
    mavenCentral()
  }
}

加入你要引用的文件信息:

dependencies {
  compile '[GROUP_ID]:[ARTIFACT_ID]:[VERSION]'
}

执行命令:

gradle dependencies 或 ./gradlew dependencies 安装依赖
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值