AS Gradle配置

androidstudio中各种gradle配置解释说明

项目的Project的配置

buildscript { //设置脚本的运行环境
    repositories { //支持java 依赖库管理(maven),用于项目的依赖
        jcenter()
        mavenCentral()

        google()
    }
    dependencies { //依赖包的定义。支持maven/ivy,远程,本地库,也支持单文件,如果前面定义了repositories{}maven 库,使用maven的依赖的时候只需要按照用类似于com.android.tools.build:gradle:2.1,gradle 就会自动的往远程库下载相应的依赖,就是给studio制定gradle 版本
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.0.0'

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

allprojects {//全局设置(项目根目录的build.gradle)
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        google()
    }
}

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

ext {//设置全局参数
    sdk = 23
    buildTools = "26.0.2"
    minSdk = 15
    libraryVersion = "1.0.2"
    supportVersion = "25.1.0"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

在MyApp/app/build.gradle里面使用参数

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
}
  • 1
  • 2
  • 3
  • 4

依赖管理

 仓库
 预设配置仓库
repositories {
    jcenter()
     google()
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
远程仓库
repositories {
    maven {
       maven { url "https://jitpack.io" }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
本地仓库

repositories {
    maven {
        url "../repo"
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
   本地依赖
   项目文件依赖
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
  • 1
  • 2
  • 3
  • 4
  • 5

项目的Module的配置

apply plugin: 'com.android.application' //这个代表当前modle是一个app而不是一个library
apply plugin: 'org.greenrobot.greendao'

android {
    signingConfigs { //签名配置

        debug { //debug版签名配置
            keyAlias 'mima' //key别名
            keyPassword 'mima' //key密码
            storeFile file('E:/workspace/xuexi/5xuexi.jks') //密钥文件路径
            storePassword 'mima' //密钥文件密码
            }
       release {//发布版签名配置
            keyAlias 'mima' 
            keyPassword 'mima' 
            storeFile file('E:/workspace/xuexi/5xuexi.jks') 
            storePassword 'mima' 
          }
        }
    }
    compileSdkVersion 23 //编译的SDK版本
    buildToolsVersion "26.0.2" //编译的Tools版本
    defaultConfig {//默认配置
        applicationId "com.sj.yinjiaoyun.xuexi" //应用程序的包名
        minSdkVersion 15 //支持的最低版本
        targetSdkVersion 23 //支持的目标版本
        versionCode 21 //版本号
        versionName "2.4" //版本名
        multiDexEnabled true //混淆开启
    }
    greendao { //数据库
        schemaVersion 1
        targetGenDir 'src/main/java'
        daoPackage 'com.sj.yinjiaoyun.xuexi.greedao.gen'

    }
    buildTypes { //build类型
        release { //发布
            minifyEnabled true //混淆开启
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' //指定混淆规则文件
 signingConfig signingConfigs.release//设置签名信息
        }
        debug { //调试
            minifyEnabled false 
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //项目文件依赖--(本地依赖)编译lib目录下的.jar文件
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile project(':circlerefresh') //编译附加的项目
    compile files('libs/jcore-android_v1.1.0.jar') //引入对应的文件
    compile 'com.android.support:design:23.3.0' //编译来自support的开源库



}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值