zoukankan      html  css  js  c++  java
  • Android学习——day4

    详解build.gradle文件

    一个android项目工程里面一般有两个build.gradle文件,一个位于根目录,一个位于app文件夹内

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

     1 buildscript {
     2     repositories {
     3         jcenter()
     4     }
     5     dependencies {
     6         classpath 'com.android.tools.build:gradle:2.2.0'
     7     }
     8 }
     9 
    10 allprojects {
    11     repositories {
    12         jcenter()
    13     }
    14 }

    (1)repositories的闭包中声明的jcenter()配置是一个代码托管仓库,声明后可以引用任何jcenter上的开源项目

    (2)dependencies闭包中使用classpath来构建Android项目需要声明插件:com.android.tools.build:gradle:2.2.0。其中,最后面是插件版本号


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

    
    
    apply plugin: 'com.android.application'

    android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
    applicationId "com.example.a86147.helloworld"
    minSdkVersion 15
    targetSdkVersion 24
    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:24.2.1'
    testCompile 'junit:junit:4.12'
    }
     

    1.apply plugin: ‘com.android.application’
    与之相对应的是apply plugin: ‘com.android.library’。com.android.application表示这是一个应用程序模块,即可以直接运行的。com.android.library表示这是一个库模块,即只能作为代码库依附于别的应用程序模块来运行。

    2.android闭包:配置项目构建的各种属性

    (1)compileSdkVersion:用于指定项目的编译版本。24表示使用Android 7.0系统的SDK编译

    (2)buildToolsVersion:用于指定项目构建工具的版本。

    (3)defalultConfig闭包:

    • applicationId:指定项目的包名,可以对指定过的进行修改

    • minSdkVersion:制定项目最低兼容的Android系统版本

    • targetSdkVersion:目标版本,也就是说编写这个工程兼容的最好版本,但是在更高版本的设备上也可以运行

    • versionCode:指定项目的版本号

    • versionName:指定项目的版本名

    (4)buildTypes闭包:用于指定生成安装文件的相关配置,通常有两个字闭包:debugrelease

    • debug闭包用于指定生成测试板安装文件的配置,可以忽略不写

    • release闭包用于指定生成正式版安装文件的配置。

                       minifyEnabled:指定是否对项目的代码进行混淆,true表示混淆,false表示不混淆

                       proguardFiles:指定混淆时使用的规则文件。这里的proguard-android.txt是在Android SDK目录下的,是所有项目通用的混淆规则。proguard-rules.pro是在当前项目的根目录下的,可以编写当前项目特有的混淆规则。 通过Android Studio直接运行项目生成的都是测试版安装文件

    3.dependencies闭包:指定当前项目所有的依赖关系

    通常Android Studio项目一共有3种依赖方式:本地依赖、库依赖和远程依赖。

    • 本地依赖对本地的jar或目录添加依赖关系

    • 库依赖对项目中的库模块添加依赖关系

    • 远程依赖对jcenter库上的开源项目添加依赖关系

  • 相关阅读:
    获取CheckBox的Text值
    动态绑定数据至Html Table
    二次事件并细化功能
    ASP.NET MVC的JavaScriptResult
    Google Earth 8.0
    ASP.NET MVC的ContentResult
    ASP.NET MVC使用input标签上传文件
    处理动态SQL语句的参数
    Infor SyteLine如何快速锁定用户
    执行git push出现"Everything up-to-date"
  • 原文地址:https://www.cnblogs.com/znjy/p/14279925.html
Copyright © 2011-2022 走看看