-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Modifying Android xml files
wchen342 edited this page Nov 9, 2021
·
1 revision
The gn template brave_xml_preprocessor can be used to process XML resources files before it is compiled.
A target brave_java_xml_preprocess_resources has already been set up. To add a new XML resource file for pre-processing,
- Add the XML file path to
brave_java_preprocess_xml_sourcesinandroid/brave_java_resources.gni. - Add a python file to where you want, and add the path to the python file to
brave_java_preprocess_module_sourcesinandroid/brave_java_resources.gni. - In the newly added python file, define a function
_ProcessXML(root)which takes one single argumentrootas the root element of the XML root etree Element. The function shall return the processed rootElement.- You can do whatever processing you want with the Element. For example, insert a new node by parsing a string using fromstring(text) and insert it at a given position with insert(index, subelement).
- Remember to register namespaces. You will need to at least register the
androidns by doingas well as passingns = { 'android' : 'http://schemas.android.com/apk/res/android' } for prefix, uri in ns.items(): ET.register_namespace(prefix, uri)namespaces=nsto all find(match) calls.
- You can then use the processed resource with a
brave_prefix. For example,R.main_menuwill now becomeR.brave_main_menu.
See this branch for a simple example for what you can do.