Android Plugin DSL Reference 参考文档 :
在 Splits 配置中 , 有
个脚本块配置 ,
参考 android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.Splits.html 文档 ;
Splits ( build.gradle#android#splits ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.Splits.html
DensitySplitOptions ( build.gradle#android#splits#density ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.DensitySplitOptions.html
Splits#density {} 脚本块配置 用于配置 根据 屏幕像素密度 进行 apk 分包的设置 ;
Splits#density {} 脚本块配置原型 : 配置 屏幕像素密度 分包设置 ;
density { }
Configures density split settings.
配置 屏幕像素密度 分包设置
Delegates to:
DensitySplitOptions from density
该脚本块主要是配置 Splits#density 属性 , 其类型是 DensitySplitOptions ;
Splits#density 属性 原型如下 :
DensitySplitOptions density
Density settings.
Splits#density 配置使用示例 : 下面的章节会详细讲解 DensitySplitOptions 配置的属性及方法细节 ;
android {
splits {
abi {
enable true
// 重置所有配置
reset()
// 只生成 x86 和 armeabi-v7a 架构的 apk
include 'x86', 'armeabi-v7a'
universalApk true
}
density {
enable true
// 排除 xhdpi 的打包 apk
exclude 'xhdpi'
}
}
}
使用效果 : 编译 apk 文件时 , 会为每个 屏幕像素密度 生成独立的 apk 文件 ;
如 : 为 xhdpi 生成一个专门在 xhdpi 设备上运行的 apk ;
默认是生成所有屏幕像素密度的 apk 包 , 如果设置了 exclude 'xhdpi'
, 就不会生成 该 密度 对应的 apk , 生成其它 ldpi
mdpi
hdpi
xxhdpi
xxxhdpi
的 apk 文件 ;
DensitySplitOptions ( build.gradle#android#splits#density ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.DensitySplitOptions.html
在 build.gradle#android#splits#density 中配置的类型是 DensitySplitOptions 配置 , 该配置的属性与方法如下 :
Properties
Property Description
applicableFilters
Returns a list of all applicable filters for this dimension.
返回此维度所有适用筛选器的列表。
auto
Whether the build system should determine the splits based on the "language-*" folders in the resources.
构建系统是否应根据参考资料中的“language-*”文件夹确定拆分。
compatibleScreens
A list of compatible screens.
兼容屏幕列表。
enable
Whether to split in this dimension.
是否在此维度中拆分。
Methods
Method Description
exclude(excludes)
excludes some values
排除某些值
include(includes)
includes some values
包括一些值
reset()
Resets the list of included split configuration.
重置包含的拆分配置列表。
上述方法属性的具体用法 , 参考 https://developer.android.com/studio/build/configure-apk-splits 文档 ;