有勇气的牛排博客

Android Stdio换源以及配置项目

有勇气的牛排 1177 安卓 2021-10-20 14:54:40

换阿里源

  1. 对特定项目生效,在项目中的build.gradle修改内容
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' } } 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 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' } } } task clean(type: Delete) { delete rootProject.buildDir }
  1. 对所有项目生效
    C:\Users\Administrator\.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('https://repo1.maven.org/maven2')) { project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL." remove repo } if (url.startsWith('https://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 } } }

方法二(待测)

换源

build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() maven { url 'https://jitpack.io' } } dependencies { classpath "com.android.tools.build:gradle:4.0.1" classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10' // 资源混淆插件:https://github.com/shwenzhang/AndResGuard classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.17' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' } maven { url 'https://maven.aliyun.com/nexus/content/repositories/central/' } maven { url 'https://dl.bintray.com/getactivity/maven/' } maven { url 'https://dl.bintray.com/umsdk/release' } maven { url 'https://maven.google.com' } maven { url 'https://jitpack.io' } } } task clean(type: Delete) { delete rootProject.buildDir }

config.gradle

// 通用配置 android { compileSdkVersion 31 defaultConfig { minSdkVersion 16 targetSdkVersion 31 versionName '1.0' versionCode 10 } // 支持 Java JDK 8 compileOptions { targetCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8 } // 设置存放 so 文件的目录 sourceSets { main { jniLibs.srcDirs = ['libs'] } } } dependencies { // 依赖 libs 目录下所有 jar 包 implementation fileTree(include: ['*.jar'], dir: 'libs') // 依赖 libs 目录下所有 aar 包 implementation fileTree(include: ['*.aar'], dir: 'libs') // 谷歌兼容库:https://developer.android.google.cn/jetpack/androidx/releases/appcompat?hl=zh-cn implementation 'androidx.appcompat:appcompat:1.3.0-alpha01' implementation 'com.google.android.material:material:1.3.0-alpha01' }

参考文章:
https://www.cnblogs.com/qianmaoliugou/p/12369654.html


留言

专栏
文章
加入群聊