mudule build.gradle 模块级构建文件

google 文档说明 对应地址: https://developer.android.com/studio/build

模块级 build.gradle 文件位于每个 project/module/ 目录下,用于为其所在的特定模块配置构建设置。您可以通过配置这些构建设置提供自定义打包选项(如额外的构建类型和产品变种),以及替换 main/ 应用清单或顶层 build.gradle 文件中的设置。

/**
 * The first line in the build configuration applies the Android plugin for
 * Gradle to this build and makes the android block available to specify
 * Android-specific build options.
翻译后:
构建配置的第一行将Android插件应用于 升级到此版本,并使android块可用于指定 特定于Android的构建选项
自己翻译:
构建配置的第一行通过Gradle 构建使用Android插件,可使android块用于指定 特定的Android构建选项。
 */

apply plugin: 'com.android.application'

/**
 * The android block is where you configure all your Android-specific
 * build options.
翻译后:
android块是您配置所有特定于Android的地方 构建选项。
 */

android {

  /**
   * compileSdkVersion specifies the Android API level Gradle should use to
   * compile your app. This means your app can use the API features included in
   * this API level and lower.
翻译后:
编译Sdk版本指定Gradle编译您的应用程序使用的Android API级别 。这意味着您的应用可以使用此API级别及更低的API功能 。
   */

  compileSdkVersion 28

  /**
   * buildToolsVersion specifies the version of the SDK build tools, command-line
   * utilities, and compiler that Gradle should use to build your app. You need to
   * download the build tools using the SDK Manager.
   *
   * This property is optional because the plugin uses a recommended version of
   * the build tools by default.
翻译后:
buildToolsVersion指定SDK构建工具的版本,命令行和 Gradle用于构建程序的编译器。你需要下载构建工具来使用SDK Manager。

此属性是可选的,因为插件使用推荐的版本 默认情况下为构建工具
   */

  buildToolsVersion "29.0.2"

  /**
   * The defaultConfig block encapsulates default settings and entries for all
   * build variants, and can override some attributes in main/AndroidManifest.xml
   * dynamically from the build system. You can configure product flavors to override
   * these values for different versions of your app.
翻译后:
defaultConfig块对于构建变体所有封装了所有的默认设置和条目 ,并且可以动态地构建系统并覆盖main / AndroidManifest.xml中的某些属性 。您可以配置产品口味以覆盖
这些值适用于您应用的不同版本
   */

  defaultConfig {

    /**
     * applicationId uniquely identifies the package for publishing.
     * However, your source code should still reference the package name
     * defined by the package attribute in the main/AndroidManifest.xml file.
翻译后:
applicationId唯一标识要发布的包。 但是,您的源代码仍应引用程序包名称main / AndroidManifest.xml文件中的package属性定义。
     */

    applicationId 'com.example.myapp'

    // Defines the minimum API level required to run the app.
翻译:
  定义app最低支持的版本
    minSdkVersion 15

    // Specifies the API level used to test the app.
翻译:
指定用于测试应用程序的API级别
    targetSdkVersion 28

    // Defines the version number of your app.
翻译为:
定义应用程序的版本号
    versionCode 1

    // Defines a user-friendly version name for your app.
//为您的应用程序定义一个用户友好的版本名称
    versionName "1.0"
  }

  /**
   * The buildTypes block is where you can configure multiple build types.
   * By default, the build system defines two build types: debug and release. The
   * debug build type is not explicitly shown in the default build configuration,
   * but it includes debugging tools and is signed with the debug key. The release
   * build type applies Proguard settings and is not signed by default.
翻译后:
您可以在buildTypes块中配置多种构建类型。
默认情况下,构建系统定义了两种构建类型:调试和发布。
默认生成配置中,debug调试构建类型虽然没有在显式展示,
但它包含调试工具,并使用调试键签名。release发布
构建类型应用混淆设置,默认没有签名。
   */

  buildTypes {

    /**
     * By default, Android Studio configures the release build type to enable code
     * shrinking, using minifyEnabled, and specifies the default Proguard rules file.
翻译后:
默认情况下,Android Studio将发布版本类型配置为启用代码 使用minifyEnabled缩小,并指定默认的Proguard 混淆规则文件。
     */

    release {
        minifyEnabled true // Enables code shrinking for the release build type.
翻译后:
为发布版本类型启用代码收缩。
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }

  /**
   * The productFlavors block is where you can configure multiple product flavors.
   * This allows you to create different versions of your app that can
   * override the defaultConfig block with their own settings. Product flavors
   * are optional, and the build system does not create them by default.
   *
   * This example creates a free and paid product flavor. Each product flavor
   * then specifies its own application ID, so that they can exist on the Google
   * Play Store, or an Android device, simultaneously.
   *
   * If you declare product flavors, you must also declare flavor dimensions
   * and assign each flavor to a flavor dimension.
翻译后:
在productflavor(各种产品)块中,您可以配置多种产品口味。
其允许你创建不同版本的应用程序并可以
用其的设置覆盖defaultConfig (默认配置)块。产品口味
是可选的,构建系统默认不创建它们。

本示例创建了免费和付费的产品样式。每种产品的味道 可以指定其自己的应用程序ID,以便它们可以在Google Play商店或Android设备同时存在。

如果声明产品口味,则还必须声明口味尺寸并将每种风味分配给风味维度。
   */

  flavorDimensions "tier"
  productFlavors {
    free {
      dimension "tier"
      applicationId 'com.example.myapp.free'
    }

    paid {
      dimension "tier"
      applicationId 'com.example.myapp.paid'
    }
  }

  /**
   * The splits block is where you can configure different APK builds that
   * each contain only code and resources for a supported screen density or
   * ABI. You'll also need to configure your build so that each APK has a
   * different versionCode.
翻译后:
拆分块是您可以配置不同APK版本的地方 ,每个仅包含用于支持的屏幕密度的代码和资源,或者 不同类型的ABI。您还需要配置自己的版本,以便每个APK都有一个 不同的versionCode。
   */

  splits {
    // Settings to build multiple APKs based on screen density.
翻译后:
用于根据屏幕密度构建多个APK的设置
    density {

      // Enable or disable building multiple APKs.
翻译后:
启用或禁用构建多个APK
      enable false

      // Exclude these densities when building multiple APKs.
  在构建多个APK时排除这些密度
      exclude "ldpi", "tvdpi", "xxxhdpi", "400dpi", "560dpi"
    }
  }
}

/**
 * The dependencies block in the module-level build configuration file
 * specifies dependencies required to build only the module itself.
 * To learn more, go to Add build dependencies.
翻译后:
自己 :模块本身需要的依赖资源。
模块级构建配置文件中的依赖项块 指定仅构建模块本身所需的依赖项。 要了解更多信息,请转到添加构建依赖项。
 */

dependencies {
    implementation project(":lib")
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容