Gradle文件配置(其它配置)

来源:互联网 发布:淘宝网店装修模板 编辑:程序博客网 时间:2024/05/21 17:22

1.packagingOptions

使用packagingOptions排除不想添加到apk中的文件

 packagingOptions {        exclude 'META-INF/DEPENDENCIES.txt'        exclude 'META-INF/LICENSE.txt'        exclude 'META-INF/NOTICE.txt'        exclude 'META-INF/NOTICE'        exclude 'META-INF/LICENSE'        exclude 'META-INF/DEPENDENCIES'        exclude 'META-INF/notice.txt'        exclude 'META-INF/license.txt'        exclude 'META-INF/dependencies.txt'        exclude 'META-INF/LGPL2.1'    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

2.自定义BuildConfig字段

 buildTypes {        release {            // 不显示Log            buildConfigField "boolean", "LOG_DEBUG", "false"
  • 1
  • 2
  • 3
  • 4

自定义BuidlConfig

3.删除项目中没用到的资源文件

使用场景是当项目使用了很多第三方库的时候,这些库包含了很多资源文件,但是您的项目只使用了其中一小部分

shrinkResources true
  • 1

4. Java 的版本配置

 compileOptions {        sourceCompatibility JavaVersion.VERSION_1_8        targetCompatibility JavaVersion.VERSION_1_8    }
  • 1
  • 2
  • 3
  • 4

5.lintOptions

lintOptions {        disable "InvalidPackage"        lintConfig file("lint.xml")    }
  • 1
  • 2
  • 3
  • 4

disable “InvalidPackage”作用