Android资源overlay机制

Android Overlay机制总结 Android Overlay机制 动态加载资源 阅读详情
谷歌有一个overlay机制,不修改apk或者framework源代码的情况下,实现资源的定制。
将一篇比较详细的blog粘贴过来。


                    Overlay Mechanism

The Android overlay mechanism allows the framework and package resources to be customized without changing the base packages. The customizable resourses fall into the following categories

  • Configurations (string, bool, bool-array)
  • Localization (string, string-array)
  • UI Appearance (color, drawable, layout, style, theme, animation)
  • Raw resources (audio, video, xml)

For detailed introduction on Android application resources, please refer to:

 http://developer.android.com/guide/topics/resources/available-resources.html

 

1 Add Overlay Directories for Product

1.1 Product Overlays vs Device Overlays

There are two types of overaly directories that affect a product:

  • PRODUCT_PACKAGE_OVERLAYS: used by a particular product
  • DEVICE_PACKAGE_OVERLAYS: used several products that share a common device model

The PRODUCT_PACKAGE_OVERLAYS will override the DEVICE_PACKAGE_OVERLAYS if they contain same resources, the behavior is defined by:

build/core/package.mk (Line: 93)

LOCAL_RESOURCE_DIR := \

  $(wildcard $(foreach dir, $(PRODUCT_PACKAGE_OVERLAYS), \

    $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \

  $(wildcard $(foreach dir, $(DEVICE_PACKAGE_OVERLAYS), \

    $(addprefix $(dir)/, $(LOCAL_RESOURCE_DIR)))) \

  $(LOCAL_RESOURCE_DIR)

 

1.2 Change the makefile to add overlays

To add an overlay directory to a product, change the product configuration makefile (for example: device/vendor-name/device-name/product-name.mk) to add the following lines:

PRODUCT_PACKAGE_OVERLAYS :=  device/vendor-name/device-name/product-name/overlay $(PRODUCT_PACKAGE_OVERLAYS)

 

Or:

 

DEVICE_PACKAGE_OVERLAYS :=  device/vendor-name/device-name/common/overlay $(DEVICE_PACKAGE_OVERLAYS)

 

If multiple overlay directories are required to be added, separate them with blank charactors. The directories defined first in the line will override the following directories if they contain the same set of resources.

 

1.3 Create resources under the overlay directory

To overlay the resources in a base package, the subdirectory containing the overlay resources under the overlay directory, must has the same path as the base package resource directory relative to the Android project root.

For example, if we want to overlay the resources under the base package directory:

packages/apps/Settings/res/

we need to create the directory:

/packages/apps/Settings/res/

and in the directory, put the overlay resources in the files with the same path and file names as where they are defined in the base package.

Note that:

  • For color, bool, string, array, style/theme types, the resource values are identifed by their keys, so for these types, there is no need to put the resources in a file with the same name as in the original base package.
  • For layout, animation, picture drawables and raw types, the resources are indentifed by their file name, and overlay for these resources should keep the file name same as in the base packages.

 


 

2 Check the resource in APK

After changed the overlay resources and built the target packages, sometimes we need to check if the overlay directory took effects and the values are changed in the finally generated apks.

2.2 Using AAPT

 

 

 

Usage:
aapt l[ist] [-v] [-a] file.{zip,jar,apk}
   List contents of Zip-compatible archive.
 
aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]
   badging          Print the label and icon for the app declared in APK.
   permissions      Print the permissions from the APK.
   resources        Print the resource table from the APK.
   configurations   Print the configurations in the APK.
   xmltree          Print the compiled xmls in the given assets.
   xmlstrings       Print the strings of the given compiled xml assets.

 

For example:

1. To dump string, bool values:

aapt dump resources Settings.apk

 

2. To dump a raw xml file:

aapt dump xmltree Settings.apk res/xml/appwidget_info.xml

 

3. To dump the current configurations/localizations:

aapt dump configurations Settings.apk

 

2.2 Using apktools

 

Reference: http://code.google.com/p/android-apktool/

 

 

 

 

 

 

 

 

 

Apktool v1.5.0.5a056e3 - a tool for reengineering Android apk files
Copyright 2010 Ryszard Wi??niewski
with smali v1.3.4-ibot8, and baksmali v1.3.4-ibot8
Updated by iBotPeaches
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
 
Usage: apktool [-q|--quiet OR -v|--verbose] COMMAND [...]
 
COMMANDs are:
 
    d[ecode] [OPTS] [
        Decode to
 
        OPTS:
 
        -s, --no-src
            Do not decode sources.
        -r, --no-res
            Do not decode resources.
        -d, --debug
            Decode in debug mode. Check project page for more info.
        -f, --force
            Force delete destination directory.
        -t , --frame-tag
            Try to use framework files tagged by .
        --keep-broken-res
            Use if there was an error and some resources were dropped, e.g.:
            "Invalid config flags detected. Dropping resources", but you
            want to decode them anyway, even with errors. You will have to
            fix them manually before building.
 
    b[uild] [OPTS] [] []
        Build an apk from already decoded application located in .
 
        It will automatically detect, whether files was changed and perform
        needed steps only.
 
        If you omit then current directory will be used.
        If you omit then /dist/
        will be used.
 
        OPTS:
 
        -f, --force-all
            Skip changes detection and build all files.
        -d, --debug
            Build in debug mode. Check project page for more info.
 
    if|install-framework []
        Install framework file to your system.
 
For additional info, see: https://github.com/iBotPeaches/brut.apktool
For smali/baksmali info, see: http://code.google.com/p/smali/

 

2.3 Using dumpres

 


 

3 More on AAPT and Overlay

3.1 How overlay works

While building the package APKs, the overlay directories are passed to aapt command lines using -S options in the same order as they are defined in 

PRODUCT_PACKAGE_OVERLAYS and DEVICE_PACKAGE_OVERLAYS.

For example, while building the Settings APK, the following command are executed:

 

out/host/linux-x86/bin/aapt package -u  -z \
         -M packages/apps/Settings/AndroidManifest.xml \
         -S device/vendor-name/device-name/product-name/overlay/packages/apps/Settings/res \
         -S vendor/vendor-name/media/common/overlay/packages/apps/Settings/res -S packages/apps/Settings/res \
         -I out/target/common/obj/APPS/framework-res_intermediates/package-export.apk \
         --min-sdk-version 16 --target-sdk-version 16 --product default \
         --version-code 16 --version-name 4.1.2-eng.xxxx.20121121.152327 \
         -F out/target/product/product-name/obj/APPS/Settings_intermediates/package.apk

Note: some overlay directories that don't contain the Settings resources will be filtered first, and do not appear in the above command line.

 

3.2 Add extra resources in Overlay

Though not recommanded, we can add new resources in overlay directory, for example, if base package Settings doesn't define a bool value with key no_such_key, we can add it in the overlay file bool.xml like this:

 
  
    ... ...
   
    true
    ... ...
 
 

 

If the add-resource line is missing, aapt tool will complain while creating the apk file:

 

device/vendor-name/device-name/product-name/overlay/packages/apps/Settings/res/values/bools.xml:30: error: Resource at no_such_key appears in overlay but \not in the base package; use to add.

 

Another way to avoid the complaint is to run aapt with the option:

 

--auto-add-overlay
    Automatically add resources that are only in overlays.

Android Overlay 机制解析 android Overlay 阅读详情

相关推荐

深入剖析Android Overlay机制:从静态到动态的资源替换实践

本文深入剖析Android Overlay机制,详细介绍了静态Overlay(SRO)与运行时Overlay(RRO)的工作原理与实践方法。通过具体配置示例和命令行操作,阐述了如何利用该机制实现系统资源替换、主题定制与功能开关,并提供了优先级管理、ID映射等进阶调试技巧,是进行Android系统深度定制的核心指南。

weixin_29248611的博客 202

资源覆盖-overlay机制

资源覆盖-overlay机制

小Q的博客 4673

深入剖析Android Overlay机制:静态与动态资源替换实战指南

本文深入剖析Android Overlay机制,详细对比了静态Overlay(SRO)与运行时Overlay(RRO)的核心原理与应用场景。通过实战指南,手把手教你如何在不修改原始APK源码的情况下,灵活替换系统或应用资源,实现主题定制、多版本适配等功能,并提供了关键的adb调试命令与常见问题解决方案。

weixin_29299807的博客 264

android overlay机制实践

前言 最近在做launcher时有一个需求是通过overlay机制实现替换主题,中间遇到了不少问题,这里记录一下自己以后能用到,也希望能帮助有需要的同学。我使用的是android11系统,参考官方文档 https://source.android.google.cn/devices/architecture/rros?hl=zh-cn 概述 android overlay是一种资源的动态替换机制,它的工作原理是将叠加层软件包中定义的资源映射到目标软件包中定义的资源。当应用尝试解析目标软件包中资源的值时,系

qq_41818873的博客 7746

深入探索Android Overlay机制:静态与动态资源替换实战指南

本文深入解析Android Overlay机制,详细对比静态Overlay(SRO)与运行时Overlay(RRO)的核心原理与应用场景。通过实战指南,手把手教你如何配置SRO进行编译时资源替换,以及如何开发和管理RRO APK实现动态主题切换与A/B测试,帮助开发者高效、安全地定制Android系统界面与资源。

weixin_29215815的博客 420

告别硬编码!用Android Overlay机制动态替换App资源(附SRO/RRO实战配置)

本文深入解析Android Overlay机制,教你如何通过SRO/RRO动态替换App资源,告别硬编码。详细对比静态与运行时Overlay的适用场景,提供实战配置步骤和性能优化建议,助力实现动态主题切换和多语言支持。

weixin_30681121的博客 327

Android Overlay机制

是一种资源替换机制,它能在不重新打包 apk 的情况下,覆盖替换 res/ 下的字符和图片等资源。分为 静态Overlay (Static Resource Overlay) 和 运行时 Overlay (Runtime Resource Overlay)。两种 Overlay 方式,都需要资源 id 对应上。大白话就是要替换的资源名称一样、字符串的 id 一样。:发生在编译时,需要在 Aosp 源码中配置。):发生在运行时,可以直接覆盖替换其他 apk 的资源而不需要其源码。

weixin_44021334的博客 6167

gsplat在windows本地部署

3DGS的cuda提效和优化内存的版本gsplat,使得在有一定GPU计算能力的电脑上也能够尝尝3DGS的效果。我在2025年的开年之初尝试配置过gsplat,由于过程中遇到很多问题,最终还是有一些windows上字符编码的问题,没有跑通,最近看gsplat的github更新了3DGUT,优化了反射和二次折射,以及适用于非线性相机模型,如鱼眼相机等。在data目录下下载好了360_v2的数据,进入之后images文件夹是原始分辨率的图像,images_2是下采样系数为2的数据,以此类推。

yuleaf_csdn的博客 2384

android资源替换方案overlay,android开发 overlay机制研究

一.overlay 介绍android overlay 机制允许在不修改packages中apk的情况下,来自定义 framework和package中的资源文件,实现资源的定制。来达到显示不同的ui的目的.二.overlay编译流程分析1.添加overlay 目录1.1 product overlays与device overlays有两种不同的overaly目录定义,来影响最终的效果:prod...

weixin_42463199的博客 3235

海康工业相机LabVIEW二次开发实战——参数配置优化与图像高效存储

本文详细介绍了海康工业相机在LabVIEW平台上的二次开发实战,重点解析了相机参数配置的优化方法与图像高效存储策略。通过剖析曝光、增益、触发模式等核心参数的设置逻辑,并结合生产者-消费者设计模式,指导开发者构建稳定、高效的图像采集与异步存储流程,有效提升工业视觉项目的开发效率与系统稳定性。

weixin_29306317的博客 235

从零开始:Doherty功率放大器的ADS仿真实践指南

本文详细介绍了Doherty功率放大器在ADS中的仿真设计流程,从基础原理到实际工程应用。通过负载调制技术,Doherty结构显著提高了功率放大器的效率,特别适合处理高峰均比信号。文章包含ADS环境搭建、对称与非对称设计、常见问题调试等实用内容,为射频工程师提供全面的实践指南。

weixin_29313547的博客 709

android 标签overlay,Android点滴积累系列--资源overlay机制(转)

OverlayMechanismThe Android overlay mechanism allows the frameworkand package resources to be customized without changing the basepackages. The customizable resourses fall into the followingcategories...

weixin_42522131的博客 434

告别谷歌!QGC地面站v4.0.x保姆级教程:用高德/天地图瓦片替换老旧地图源

本文提供QGroundControl(QGC)地面站v4.0.x的详细教程,指导用户如何用高德地图和天地图瓦片替换默认地图源,解决数据陈旧、访问不稳定等问题。教程涵盖环境配置、源码修改、地图集成及性能优化,帮助无人机开发者打造稳定高效的中文地图解决方案。

weixin_30836759的博客 513

Android 运行时资源替换机制RRO(Runtime Resource Overlay )

1. RRO作用 Android开发中,遇到一个没有代码的三方apk,想要修改其某个button或view等的文字显示或背景或添加某种语言下的翻译等,此机制就能大展身手了 2.RRO介绍 Android5.0提供RRO机制,能在 apk 运行时,自动加载需要定制的资源,而不加载原有的资源,因而可以通过overlay方式修改无代码的第三方apk的资源文件 应用...

kk的博客 4911

Odoo 集成ReportBro报表设计器支持13,14,15,16,17,18,19

Odoo 集成ReportBro零代码报表设计器,ReportBro设计器 一个用于创建PDF和XLSX报告模板的javascript插件。

zxltwins的博客 3393

【信息科学与工程学】信息科学领域——第一百三十三篇 半导体器件物理与电子封装01

③ 载流子浓度:n=∫Ec​∞​gc​(E)f(E)dE,f(E)=1+exp((E−EF​)/kB​T)1​,非简并时 n=Nc​exp(−kB​TEc​−EF​​),Nc​=2(ℏ22πme∗​kB​T​)3/2。简并时需用Fermi-Dirac积分 F1/2​(η)=π​2​∫0∞​1+ex−ηx​​dx,n=Nc​π​2​F1/2​(η),η=(EF​−Ec​)/kB​T。对于低维系统:2D g2D​(E)=πℏ2m∗​Θ(E−Ec​),1D g1D​(E)=πℏ1​E2m∗​​。

weixin_49199313的博客 559

Android点滴积累系列--资源overlay机制(转)

谷歌有一个overlay机制,不修改apk或者framework源代码的情况下,实现资源的定制。 将一篇比较详细的blog粘贴过来。 http://mmmyddd.freeshell.net/wiki/android/overlay.html                  OverlayMechanism The Android overlay mechanis

edmond999的专栏 1708

减法平均优化器(SABO)算法详解:从数学原理到工程应用

减法平均优化器(SABO)是一种基于数学概念的新型元启发式优化算法,由Trojanovský和Dehghani于2023年提出。该算法通过v-减法运算和平均值计算实现搜索优化,核心创新是采用目标函数值差异符号引导搜索方向。SABO具有参数少、结构简单、收敛快等特点,在高维复杂问题中表现优异。算法通过种群平均值保持多样性,利用符号函数确保搜索方向改进,自然平衡探索与开发。MATLAB实现显示其计算复杂度为O(N²·D),与主流群体智能算法相当。SABO不依赖生物或物理隐喻,数学基础坚实,在工程优化和机器学习领

qq_42212808的博客 174

告别重新打包!用Android Overlay机制动态替换App资源(附SRO/RRO实战)

本文深入解析Android Overlay机制,详细介绍如何通过静态Overlay(SRO)和运行时Overlay(RRO)动态替换应用资源,实现零停机更新和快速修复。文章包含实战指南和配置示例,帮助开发者高效利用这一技术解决资源更新难题,提升应用维护效率。

weixin_30617737的博客 336

ROS Motion Planning运动规划库安装方法及进阶使用方法详细介绍

​今天偶然发现了一个优质的运动规划库:ai-winter/ros_motion_planning,比较适合从事ROS移动机器人运动规划研究领域的小伙伴学习和使用,相比于莱斯大学Kavraki实验室提供的开源的著名运动规划库OMPL、或着我之前介绍过的zhm-real开源的zhm-real/MotionPlanning和zhm-real/PathPlanning运动规划库,今天介绍的ROS Motion Planning运动规划库与ROS机器人中常用的Navigation导航框架的兼容性更好,库中的运动规划

慕羽★的博客 5588

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

别再傻傻改源码了!用Android Overlay机制(SRO/RRO)5分钟搞定系统默认资源替换

本文详细介绍了Android Overlay机制(SRO/RRO)在系统默认资源替换中的应用,帮助开发者无需修改源码即可快速实现资源覆盖。通过对比直接修改源码与Overlay机制的优劣,结合实际案例和操作步骤,展示了如何利用SRO和RRO提升开发效率,避免版本兼容性问题,并提供了资源替换的决策矩阵和避坑指南。

weixin_30800987的博客 480

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Android平台Overlay机制

Android overlay 机制允许在不修改packages中apk的情况下,来自定义 framework和package中的资源文件,实现资源的定制。来达到显示不同的UI得目的(如MIUI)。 以下几类能够通过该机制定义: (1),Configurations (string, bool...

112

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Overlay机制

Android overlay 机制允许在不修改packages中apk的情况下,来自定义 framework和package中的资源文件,实现资源的定制。来达到显示不同的UI得目的(如MIUI)。      以下几类能够通过该机制定义: Configurations (string, bool, bool-array)Localization (string, string-ar

Harric 3768

Android Resources Overlay Mechanism

http://mmmyddd.freeshell.net/wiki/android/overlay.html Overlay Mechanism The Android overlay mechanism allows the framework andpackage resources to be customized without changing the basepackages.

thinkinwm的专栏 2461

Android 预置应用overlay机制使用

Android 预置应用overlay机制使用

wg_mlo的博客 814
上一篇: Service与Android系统设计(7)--- Binder驱动
下一篇: Adding prebuilt shared library to Android Build System
社区艺术家
博客等级 码龄18年 9粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值