【Android(安卓)Studio】Resource Merging资源合并规则
16lz
2021-12-04
Resource Merging
The Gradle-base build system uses a new merging mechanism for resources. In previous build system, merging was done by passing a list of resource folders to aaptwhich acted as overlays, alongside the --auto-add-overlayto ensure that new resources in the overlays would be automatically added (default behavior is for overlays is to only override existing resources, not create new ones). One of the goals of the Gradle-based build system was providing more flexibility, and one frequently asked feature request was the ability to have more than one resources folders. aapt is not able to handle this so the new build system introduces a new merging mechanism that is run ahead of aaptand generates a single, merged, resources folder that is fed to aapt. This merging has the advantage of being incremental, both through Gradle's input/output change detection, and in the way it is implemented (ie it can rerun the merge by only applying the change in a single file). The merged resources are coming from 3 types of sources:
Priority OrderThe priority order is the following:BuildType -> Flavor -> main -> Dependencies. This means that if a resource is declared in both the Build Type and in main, the one from Build Type will be selected. Note that for the scope of the merging, resources of the same (type, name) but different qualifiers are handled separately. This means that if src/main/reshas
Handling Multiple Resource FoldersAs mentioned above, each sourceSet can define multiple resource folders. For instance:android.sourceSets { main.res.srcDirs = ['src/main/res', src/main/res2'] } In this case, both resource folders have the same priority. This means that if a resource is declared in both folders, the merge will fail and an error will be reported. Priority Order for Library DependenciesWith transitive dependencies, the actual set of Library Projects seen by a project is not a flat list but a graph. However the merging mechanism only handles a flat priority list. If we consider the following example of dependencies:Project -> A, B (meaning A higher priority than B) A -> C, D B -> CThe flat list passed to the merger will be A, D, B, C This ensures that both A and B overrides C. |
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer