Reputation: 7207
A lot of configurations go into AndroidManifest.xml
file. For many applications some of those configurations are the same. For example this provider that is required to access file providers for android versions upper than 7:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/paths"/>
</provider>
This is not application specific. It's desired to have this fragment of XML somewhere, and reuse it across many applications.
I can't find anything related to reusing XML fragments across many AndroidManifest.xml files. Can we do that?
Update: This question is not about Android Fragments. I'm talking about XML code blocks. I'm trying to apply DRY (do not repeat yourself) principle to AndroidManifest.xml
files across many projects.
Upvotes: 2
Views: 174
Reputation: 2607
I think there is no such way for not repeating xml code blocks. There is a concept that let's make you free from writing same code multiple times. Android studio will do it by itself. you just need to write a small keyword. The concept is called Live Templates
in android studio.
For creating template, go to File -> Settings -> Editor -> Live Templates. Then click +
button located at right side and select Live Template
. In Abbreviation put shortcut keyword (e.g. provider) and put your code in Template Text
and also define XML
as a template context. It's Important to define context!. That's all!
Now whenever you want to use the same code you can write Abbreviation (e.g. provider) in your XML file and your whole Template Text
code will be pasted there.
Upvotes: 1