mudule build.gradle 模塊級構(gòu)建文件

google 文檔說明 對應(yīng)地址: https://developer.android.com/studio/build

模塊級 build.gradle 文件位于每個 project/module/ 目錄下,用于為其所在的特定模塊配置構(gòu)建設(shè)置。您可以通過配置這些構(gòu)建設(shè)置提供自定義打包選項(如額外的構(gòu)建類型和產(chǎn)品變種),以及替換 main/ 應(yīng)用清單或頂層 build.gradle 文件中的設(shè)置。

/**
 * 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.
翻譯后:
構(gòu)建配置的第一行將Android插件應(yīng)用于 升級到此版本,并使android塊可用于指定 特定于Android的構(gòu)建選項
自己翻譯:
構(gòu)建配置的第一行通過Gradle 構(gòu)建使用Android插件,可使android塊用于指定 特定的Android構(gòu)建選項。
 */

apply plugin: 'com.android.application'

/**
 * The android block is where you configure all your Android-specific
 * build options.
翻譯后:
android塊是您配置所有特定于Android的地方 構(gòu)建選項。
 */

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編譯您的應(yīng)用程序使用的Android API級別 。這意味著您的應(yīng)用可以使用此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構(gòu)建工具的版本,命令行和 Gradle用于構(gòu)建程序的編譯器。你需要下載構(gòu)建工具來使用SDK Manager。

此屬性是可選的,因為插件使用推薦的版本 默認(rèn)情況下為構(gòu)建工具
   */

  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塊對于構(gòu)建變體所有封裝了所有的默認(rèn)設(shè)置和條目 ,并且可以動態(tài)地構(gòu)建系統(tǒng)并覆蓋main / AndroidManifest.xml中的某些屬性 。您可以配置產(chǎn)品口味以覆蓋
這些值適用于您應(yīng)用的不同版本
   */

  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唯一標(biāo)識要發(fā)布的包。 但是,您的源代碼仍應(yīng)引用程序包名稱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.
翻譯:
指定用于測試應(yīng)用程序的API級別
    targetSdkVersion 28

    // Defines the version number of your app.
翻譯為:
定義應(yīng)用程序的版本號
    versionCode 1

    // Defines a user-friendly version name for your app.
//為您的應(yīng)用程序定義一個用戶友好的版本名稱
    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塊中配置多種構(gòu)建類型。
默認(rèn)情況下,構(gòu)建系統(tǒng)定義了兩種構(gòu)建類型:調(diào)試和發(fā)布。
默認(rèn)生成配置中,debug調(diào)試構(gòu)建類型雖然沒有在顯式展示,
但它包含調(diào)試工具,并使用調(diào)試鍵簽名。release發(fā)布
構(gòu)建類型應(yīng)用混淆設(shè)置,默認(rèn)沒有簽名。
   */

  buildTypes {

    /**
     * By default, Android Studio configures the release build type to enable code
     * shrinking, using minifyEnabled, and specifies the default Proguard rules file.
翻譯后:
默認(rèn)情況下,Android Studio將發(fā)布版本類型配置為啟用代碼 使用minifyEnabled縮小,并指定默認(rèn)的Proguard 混淆規(guī)則文件。
     */

    release {
        minifyEnabled true // Enables code shrinking for the release build type.
翻譯后:
為發(fā)布版本類型啟用代碼收縮。
        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(各種產(chǎn)品)塊中,您可以配置多種產(chǎn)品口味。
其允許你創(chuàng)建不同版本的應(yīng)用程序并可以
用其的設(shè)置覆蓋defaultConfig (默認(rèn)配置)塊。產(chǎn)品口味
是可選的,構(gòu)建系統(tǒng)默認(rèn)不創(chuàng)建它們。

本示例創(chuàng)建了免費和付費的產(chǎn)品樣式。每種產(chǎn)品的味道 可以指定其自己的應(yīng)用程序ID,以便它們可以在Google Play商店或Android設(shè)備同時存在。

如果聲明產(chǎn)品口味,則還必須聲明口味尺寸并將每種風(fēng)味分配給風(fēng)味維度。
   */

  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.
翻譯后:
用于根據(jù)屏幕密度構(gòu)建多個APK的設(shè)置
    density {

      // Enable or disable building multiple APKs.
翻譯后:
啟用或禁用構(gòu)建多個APK
      enable false

      // Exclude these densities when building multiple APKs.
  在構(gòu)建多個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.
翻譯后:
自己 :模塊本身需要的依賴資源。
模塊級構(gòu)建配置文件中的依賴項塊 指定僅構(gòu)建模塊本身所需的依賴項。 要了解更多信息,請轉(zhuǎn)到添加構(gòu)建依賴項。
 */

dependencies {
    implementation project(":lib")
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容