Android Gradle


下面这篇博文介绍了Gradle的常用仓库,以及仓库的使用方法

https://blog.csdn.net/u013005791/article/details/79098018

系统中Gradle的文件路径

在这里插入图片描述

  • Gradle自身工具所在位置:
    C:\Users\xxx\.gradle\wrapper\dists\gradle-4.10.1-all
    C:\Users\xxx.gradle\caches\4.10.1
  • Project依赖库保存的位置:
    C:\Users\xxx.gradle\caches\modules-2\files-2.1\com.android.tools.build\gradle\3.3.2

当sync gradle很慢时,可以手动下载gradle版本和依赖库,并放置到对应的位置。

Android Gradle Plugin与Gradle版本对应:

https://developer.android.google.cn/studio/releases/gradle-plugin.html#updating-plugin

Android Studio 的project中gradle相关文件

在这里插入图片描述
Project/gradle.properties: 整个Project的配置项,可以参考内部说明
Project/setting.gradel: Project中包含的所有Module都需要在此登记
Project/build.gradle: 顶层Gradle配置文件
Project/gradle/wrapper/gradle-wrapper.properties: Gradle工具的下载网址、版本,本地保存位置,
Project/Module*/build.gradle: 各Module的配置

顶层Gradle配置文件

路径:Project/buidle.gradle
下面的例子是一个Android Studio Project的顶层Gradle配置文件:build.gradle

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

buildscript {
    
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/jcenter/'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'

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

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

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

buildscript{…}配置项,指定了编译脚本用到的仓库和依赖。其中repositories{…}指定了仓库,其位置可以查看上面引用的博文。dependenies{…}指定了编译脚本的依赖库。
allprojects{…}指名了整个Project中所有的Module的仓库。

gradle仓库的引用参考下面这篇博文:

https://blog.csdn.net/csdnlijingran/article/details/80612363

Module的Gradle配置文件

下面的例子是一个Module的Gradle配置文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.test.myapplication"
        minSdkVersion 21
        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'
}

apply plugin: 'com.android.application’指明当前的Module是个application。这必须是第一句,后面的android相关的配置项才能起作用。另一个常用的plugin是com.android.library,开发库时使用。

各参数功能

https://blog.csdn.net/applepear1024/article/details/105778613

依赖

https://www.cnblogs.com/longjunhao/p/10160831.html

依赖本地Module: implementation project(":mylibrary")
依赖本地库: implementation fileTree(dir: ‘libs’, include: [’*.jar’])
依赖本地单个库: implementation files(‘libs/foo.jar’, ‘libs/bar.jar’)
依赖远程库: implementation ‘com.example.android:app-magic:12.3’

问题:

  • 怎么Lint
  • 怎么创建自己的仓库
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值