欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > Android >内容正文

Android

Android Stdio换源以及配置项目

发布时间:2025/5/22 Android 75 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Android Stdio换源以及配置项目 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

文章目录

    • 换阿里源
    • 方法二(待测)
    • 换源

换阿里源

  • 对特定项目生效,在项目中的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_URLurl 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/AndResGuardclasspath '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 31defaultConfig {minSdkVersion 16targetSdkVersion 31versionName '1.0'versionCode 10}// 支持 Java JDK 8compileOptions {targetCompatibility JavaVersion.VERSION_1_8sourceCompatibility 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-cnimplementation '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

    总结

    以上是生活随笔为你收集整理的Android Stdio换源以及配置项目的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。