android manifest 多个application,Android - 如何避免多個Manifest文件中的重復?

My project has 3 Manifest files:

我的項目有3個Manifest文件:

flavour/AndroidManifest.xml

flavourDebug/AndroidManifest.xml

flavourRelease/AndroidManifest.xml

Here is flavour/AndroidManifest.xml:

這是flavor / AndroidManifest.xml:

xmlns:android="http://schemas.android.com/apk/res/android">

Here is flavourDebug/AndroidManifest.xml:

這是flavourDebug / AndroidManifest.xml:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools">

android:allowBackup="false"

android:label="@string/app_name"

android:logo="@drawable/ic_logo"

android:theme="@style/Theme.CustomActionBarStyle"

android:networkSecurityConfig="@xml/network_security_config"

tools:replace="theme">

// Activity definitions in here

Here is flavourRelease/AndroidManifest.xml:

這是flavourRelease / AndroidManifest.xml:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools">

android:allowBackup="false"

android:label="@string/app_name"

android:logo="@drawable/ic_logo"

android:theme="@style/Theme.CustomActionBarStyle"

tools:replace="theme">

// Activity definitions in here (these are the EXACT SAME as the ones in flavourDebug/AndroidManifest.xml)

As you can see, the only difference between the Debug and Release Manifests is that the Release one is missing android:networkSecurityConfig

正如您所看到的,Debug和Release Manifests之間的唯一區別是Release 1缺少android:networkSecurityConfig

Also, the // Activity definitions in here part is exactly the same. What I want is to avoid that Activity repetition. Every time we have to change something in an Activity definition (or add a new Activity) we have to do that in 2 Manifest files (Debug and Release).

此外,//部分中的活動定義完全相同。我想要的是避免重復活動。每次我們必須在Activity定義中更改某些內容(或添加一個新的Activity)時,我們必須在2個Manifest文件(Debug和Release)中執行此操作。

I had the idea of putting everything inside the main AndroidManifest.xml file. The problem is that I would not be able to add android:networkSecurityConfig="@xml/network_security_config" only to the debug builds.

我有想法將所有內容放在主AndroidManifest.xml文件中。問題是我無法將android:networkSecurityConfig =“@ xml / network_security_config”僅添加到調試版本中。

In Android layouts, that problem is solved with the tag. Unfortunately that is not available in the Manifest.

在Android布局中,使用

標記解決了該問題。不幸的是,Manifest中沒有。

How can I solve this repetition problem?

我怎樣才能解決這個重復問題?

2 个解决方案

#1

6

You can definitely put the common part in flavour/AndroidManifest.xml and the additionnal attribute in flavourDebug/AndroidManifest.xml (and the referenced xml file in the src/flavourDebug/res/xml dir):

您絕對可以將flavor / androidManifest.xml中的公共部分和flavourDebug / AndroidManifest.xml中的additionalnal屬性(以及src / flavourDebug / res / xml目錄中引用的xml文件)放在一起:

android:networkSecurityConfig="@xml/network_security_config" />

As you are adding an attribute, it should work out of the box, without tweaking the merge rules (tools:node="merge" is the default behaviour for most elements).

在添加屬性時,它應該開箱即用,不需要調整合並規則(工具:node =“merge”是大多數元素的默認行為)。

With Android Studio 3.1 (and probably earlier versions) you can view the final manifest, and from where each attribute or element come from in the Merged manifest tab of the editor.

使用Android Studio 3.1(可能還有早期版本),您可以在編輯器的“合並清單”選項卡中查看最終清單以及每個屬性或元素的來源。

#2

1

You can of course control how to merge resource and may avoid such repetition using the main folder, check the doc here, you may be interesting by tools:node="merge" which help you control how node are merged, you'll get more info about it from teh link above.

您當然可以控制如何合並資源並可以使用主文件夾避免這種重復,請查看此處的文檔,您可能會感興趣的工具:node =“merge”可以幫助您控制節點的合並方式,您將獲得更多從上面的鏈接的信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值