换阿里源
- 对特定项目生效,在项目中的
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
}
- 对所有项目生效
在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
<h2><a id="_0"></a>换阿里源</h2>
<ol>
<li>对特定项目生效,在项目中的<code>build.gradle</code>修改内容</li>
</ol>
<pre><div class="hljs"><code class="lang-shell">// 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
}
</code></div></pre>
<ol start="2">
<li>对所有项目生效<br />
在<code>C:\Users\Administrator\.gradle</code>下创建init.gradle文件</li>
</ol>
<pre><div class="hljs"><code class="lang-shell">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
}
}
}
</code></div></pre>
<h2><a id="_63"></a>方法二(待测)</h2>
<h2><a id="_64"></a>换源</h2>
<p>build.gradle</p>
<pre><div class="hljs"><code class="lang-shell">// 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
}
</code></div></pre>
<p>config.gradle</p>
<pre><div class="hljs"><code class="lang-shell">// 通用配置
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'
}
</code></div></pre>
<p>参考文章:<br />
https://www.cnblogs.com/qianmaoliugou/p/12369654.html</p>
留言