Android Studio gradle项目文件基本配置样例

本文介绍了Android Studio项目中gradle的基本配置,包括在根目录创建dependencies.gradle文件,然后在根目录build.gradle中引入,最后详细说明了如何修改app模块的build.gradle文件。

1、根目录下创建配置文件 dependencies.gradle(同项目build.gradle同一个目录,或引用目录)

ext {
    minSdkVersion = 14
    compileSdkVersion = 27
    targetSdkVersion = 27

    hamcrestVersion = '1.3'
    junitVersion = '4.12'
    runnerVersion = '0.5'
    supportVersion = '27.0.2'

    supportV4 = "com.android.support:support-v4:$supportVersion"
    supportDesign = "com.android.support:design:$supportVersion"
    supportAnnotations = "com.android.support:support-annotations:$supportVersion"
    supportAppCompat = "com.android.support:appcompat-v7:$supportVersion"
    recyclerviewV7 = "com.android.support:recyclerview-v7:$supportVersion"

    // Test
    junit = "junit:junit:$junitVersion"
    testRunner = "com.android.support.test:runner:$runnerVersion"
    testRules = "com.android.support.test:rules:$runnerVersion"

    // Hamcrest
    hamcrestCore = "org.hamcrest:hamcrest-core:$hamcrestVersion"
    hamcrestLibrary = "org.hamcrest:hamcrest-library:$hamcrestVersion"
    hamcrestIntegration = "org.hamcrest:hamcrest-integration:$hamcrestVersion"

    // Other
    butterknife = 'com.jakewharton:butterknife:8.5.1'
    butterknifeCompiler = 'com.jakewharton:butterknife-compiler:8.5.1'

    testDep = [junit,
               hamcrestCore,
               hamcrestLibrary,
               hamcrestIntegration]

    androidTestDep = [junit,
                      testRunner,
                      testRules,
                      hamcrestCore,
                      hamcrestLibrary,
                      hamcrestIntegration]
}

2、根目录build.gradle 中添加引用

apply from: rootProject.file('dependencies.gradle')

3、app项目下build.gradle做入选如下修改

apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        applicationId "com.prolificinteractive.materialcalendarview.sample"

        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion

        versionCode 1
        versionName "1.0"
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    // You should use the commented out line below in you're application.
    // We depend on the source directly here so that development is easier.
    implementation project(':library')
    //compile 'com.prolificinteractive:material-calendarview:1.4.3'

    implementation rootProject.ext.supportAppCompat
    implementation rootProject.ext.recyclerviewV7
    implementation rootProject.ext.butterknife
    annotationProcessor rootProject.ext.butterknifeCompiler
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值