gradle的依赖包的存储位置

Android项目的app这个module下的build.gradle文件如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.administrator.myapplication"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.support:multidex:1.0.3'

}

如果项目最外层的build.gradle文件:

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

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

的 repositories 闭包写的是google()或者 jcenter()之类的,那么,对于dependencies 闭包下面声明的所有依赖,gradle在构建时会去下载,缓存在C:\Users\Administrator.gradle\caches\modules-2\files-2.1目录下,如:
在这里插入图片描述

但是,如果项目最外层的build.gradle文件:

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

buildscript {
    
    repositories {
       mavenLocal()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
    }
}

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

的 repositories 闭包写的是mavenLocal()的(就是利用本地仓库),那么gradle在构建的时候不会去下载,而是利用mavenLocal()仓库的相关依赖包进行构建,mavenLocal()仓库的默认路径是:/home/user/.m2/repository(这是Linux系统下的,windows系统类似)。

这里注意,如果mavenLocal()里的依赖包是aar格式的,那么gradle在构建的时候会将其转为jar格式,并将转换后的依赖包存储在C:\Users\Administrator.gradle\caches\transforms-1\files-1.1\目录下,如C:\Users\Administrator.gradle\caches\transforms-1\files-1.1\multidex-1.0.3.aar:
在这里插入图片描述

发布了486 篇原创文章 · 获赞 88 · 访问量 72万+

猜你喜欢

转载自blog.csdn.net/yzpbright/article/details/89001633