gradle面试

创建项目的时候会生成3个gradle文件

  • settings.gradle
  • 项目底下的build.gradle
  • app包中build.gradle或其他module的gradle
settings.gradle

对于多模块开发有用

include ':app','othermodule'
项目底下的build.gradle
//实际构建会在buildscript中
buildscript {

    //代码仓库,如一些依赖包
    repositories {
        //很有名的代码仓库
        jcenter()
    }
    dependencies {
        //定义的是gradle的安卓插件
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
//声明模块的属性
allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
app包中build.gradle

包含两个大模块android标签和dependencies标签,由apply plugin提供

//用到的android插件  官方提供  用于测试  打包
apply plugin: 'com.android.application'

android {
    //编译apk的版本
    compileSdkVersion 25
    //构建的版本  aapt等工具
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.example.administrator.lsn_11_db"
        minSdkVersion 15
        targetSdkVersion 25  //表示在某些特定的版本已经通过测试了,安卓25是稳定的版本
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

//引用第三方包
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,637评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,001评论 19 139
  • 在Android Studio的目录中,一个有三个gradle相关的文件,分别是: setting.gradle ...
    lkmc2阅读 1,943评论 0 0
  • 框架:提供一定能力的小段程序 http://www.cnblogs.com/jincheng-yangchaofa...
    姑娘请别为难小僧阅读 7,339评论 0 132
  • java.util.concurrent下的包 volatile关键字 定义:当多个线程操作共享数据时,可以保证内...
    esileme阅读 608评论 0 0