1. 程式人生 > >Suggestion: add 'tools:replace="android:name"' to element at AndroidManifest.xml

Suggestion: add 'tools:replace="android:name"' to element at AndroidManifest.xml

環境

AS 3.1.4

情形

類中建立了一個繼承自Application的類,並在AndroidManifest.xml註冊。編譯報錯,提示"Suggestion: add ‘tools:replace=“android:name”’ to element at AndroidManifest.xml"

查詢原因

通過網路搜尋,找到android:icon,android:theme等相似問題的解決方法,確定問題原因是module中同樣有一個繼承自Application的類。

解決方法

AndroidManifest.xml的根標籤下加上 xmlns:tools="http://schemas.android.com/tools"

,然後在application標籤下加入tools:replace="android:name"。如下所示

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         package="com.**">
   <application android:name="com.**.App"
                android:allowBackup="true"
                android:
icon
="@mipmap/app_icon" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" tools:replace="android:name">
</application> </manifest>