android studio换用更换国内maven库

2022/09/28 22:00:00 android 共 1373 字,约 4 分钟

自觉心是进步之母,自贱心是堕落之源,故自觉心不可无,自贱心不可有。—— 邹韬奋

因为国内特殊的网络环境, 在使用android studio的时候,如果依赖库使用默认google maven地址同步就会很慢. 本文简单记录android studio更换maven的方法

在项目的根目录的build.gradle在所有google maven前面添加ali的maven地址.

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

buildscript {

  repositories {
    // add ali maven
    maven {
      url 'http://maven.aliyun.com/nexus/content/groups/public/'
      allowInsecureProtocol true
    }
    maven {
      url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
      allowInsecureProtocol true
    }
    maven {
      url 'http://maven.aliyun.com/nexus/content/repositories/google'
      allowInsecureProtocol true
    }
    maven {
      url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
      allowInsecureProtocol true
    }

    google()
    mavenCentral()
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:7.2.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

allprojects {
  repositories {
    maven {
      url 'http://maven.aliyun.com/nexus/content/groups/public/'
      allowInsecureProtocol true
    }
    maven {
      url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
      allowInsecureProtocol true
    }
    maven {
      url 'http://maven.aliyun.com/nexus/content/repositories/google'
      allowInsecureProtocol true
    }
    maven {
      url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
      allowInsecureProtocol true
    }

    google()
    mavenCentral()
  }
}

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

文档信息

打赏一下呗

对你有帮助,那就打赏一下吧

扫码支持
扫码打赏,金额随意

文章搜索

    Post Tags Cloud

    Table of Contents