一、简介

        Android Studio是采用Gradle来构建项目的。Gradle是一个非常先进的项目构建工具,它试用了一种基于Groovy的领域特定语言(DSL)来声明项目设置,摒弃了XML(如Ant和Maven)的各种烦琐配置。

二、文件位置

        项目中一般会出现2个或者多个build.gradle文件,一个在最完全的目录下,一个在app目录下。如果切换到Android模式下则全部在Gradle Scripts.

三、详解

    1.最外层目录下的build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {    repositories { //闭包        jcenter() //代码托管库:设置之后可以在项目中轻松引用jcenter上的开源项目    }    dependencies {        classpath 'com.android.tools.build:gradle:2.2.0' //声明gradle插件,2.2.0为插件版本号        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' //开发者个人添加ButterKnife插件        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }}allprojects {    repositories {        jcenter()   //代码托管库:设置之后可以在项目中轻松引用jcenter上的开源项目   }}   

   2.app目录下的build.gradle文件

apply plugin: 'com.android.application'  //默认的应用程序模块(插件)apply plugin: 'com.neenbedankt.android-apt' //开发者添加butterkinfe插件android {    compileSdkVersion 25  //编译版本    buildToolsVersion "24.0.2"  //构建工具版本    defaultConfig {        applicationId "com.example.administrator.firstlinecode"  //包名        minSdkVersion 15    //最低兼容版本        targetSdkVersion 25    //充分测试过版本(建议版本)        versionCode 1    //版本号        versionName "1.0"    //版本名称        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false  //是否混淆(true为混淆)            //Android SDKtongyong 的混淆规则; 后面的为开发者编写的项目混淆规proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}//还有一个debug:测试版本    }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.1.0'  //远程依赖声明            compile 'com.jakewharton:butterknife:8.4.0'    //远程依赖声明            apt 'com.jakewharton:butterknife-compiler:8.4.0'        testCompile 'junit:junit:4.12'    //声明测试用例库}

  考虑到文章水平,个别C友意见特别大。1年前写的东西,现在一看的确是不适合用“详解”来标题,想想改成“初识”也很不错。
  不管怎样,多谢C友的意见!

 

 

 

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. 不吹不黑!GitHub 上帮助人们学习编码的 12 个资源,错过血亏...
  3. Android(安卓)Studio安装过程及常见问题
  4. 教你安装配置Android(安卓)Studio
  5. Android(安卓)Studio生成aar、jar包及其使用
  6. Android(安卓)studio导入eclipse项目且不改变目录结构
  7. Android版本谷歌地图改版:屏幕下方增加一个新的信息栏
  8. APP测试的内容(一)
  9. ReactNative使用code-open热更新使用详解(Android为例)

随机推荐

  1. android管理wifi
  2. Android--获取标题栏,状态栏,屏幕高度
  3. Android获取系统内核版本的方法
  4. android 属性动画之 ObjectAnimator
  5. 真心不想骂android的虚拟机
  6. Android8.1 MTK平台 截屏功能分析
  7. Android:Activity、Fragment、Adapter分别
  8. Android Studio 通用混淆
  9. android home键点击事件处理
  10. android 滑动滚动条调节音量