Andorid Studio 中的.gradle

使用Android Studio 新建的项目中有三个.gradle文件,如下:

1)  ./build.gradle //比较基础的配置 

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

buildscript {
    //声明中央仓库的源,这里可以看到是指明的jcenter(), 之前版本则是mavenCentral()
    repositories {
        jcenter()
    }
    //android gradle 插件的版本,必须要视Android Studio和SDK版本而定。
    //开发过程中就出现了"You must use a newer version of the Android Gradle plugin..."
    //这时候最简单的方式就是将版本后面添加一个"+"
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0+'

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

2) ./setting.gradle  //声明一些需要加入gradle的module

//由于只是新建的一个项目中间就一个module
include ':app'

3) ./app/build.gradle  //针对此app更细致的配置

<pre name="code" class="html">// 声明是Android程序
apply plugin: 'com.android.application'

android {
    // 编译SDK的版本
    compileSdkVersion 23
    // build tools的版本
    // (需要与本地安装版本匹配,很多人导入新的第三方库,失败的原因之一是版本不对,可以通过SDK Manager下载和查看)
    buildToolsVersion "23.0.0"

    defaultConfig {
        // 应用的包名
        applicationId "xx.xx.xx"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 310
        versionName "3.0.1"
    }
    buildTypes {
        release {
            // 是否进行混淆
            minifyEnabled false
            // 混淆文件的位置
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    // 编译libs目录下的所有jar包
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
}

以上文件里的内容只是基本配置的学习,其实还有很多自定义部分,如自动签名,多渠道打包等,后续会继续分享。

 
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值