发表文章

[最新] AS3.1.2配置gradle阿里云镜像(可用)

u010164190 24天前 2

1.对单个项目生效,在项目中app目录的build.gradle修改内容
buildscript {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        //classpath 'com.android.tools.build:gradle:3.0.1'
    }        
}

allprojects {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
}

2.对所有项目生效,在~/.gradle/下创建init.gradle文件

复制代码
allprojects{
    repositories {
        def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
        def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('http://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (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
        }
    }
}

3.赋予~/.gradle/init.gradle权限
# chmod 777 ~/.gradle/init.gradle

4.app目录下build.gradle文件里配置gradle插件路径
dependencies {
                classpath 'com.android.tools.build:gradle:3.1.2'
                //classpath 'com.android.tools.build:gradle:3.0.1'
             }
对应的目录

# /Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/3.1.2

5.真正的gradle
gradle/wrapper/gradle-wrapper.properties文件里
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

对应的安装目录
# /Applications/Android Studio.app/Contents/gradle/gradle-4.1

 

相关推荐
最新评论 (0)
返回
发表文章
u010164190
文章数
1208
评论数
0
注册排名
646551