- 如果在
app module
中新建一个类public class BaseApplication extends Application {...}
, - 然后在
lib
所在module
中也新建一个类public class LibApplication extends Application {...}
- 并且在各自的
AndroidManifest.xml
中配置了对应的android:name=".XXXApplication"
ok,经过1,2,3,并且已经
compile project(':xxxxlib')
过了。然后这时候你运行程序,会发现编译失败。
错误信息如下:
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@name value=(com.techainsh.calendarview.base.BaseApplication) from AndroidManifest.xml:7:9-45
is also present at [CalendarView:calendarlayout:unspecified] AndroidManifest.xml:12:9-72 value=(com.techainsh.calendarlayout.base.LibApplication).
Suggestion: add 'tools:replace="android:name"' to <application> element at AndroidManifest.xml:6:5-21:19 to override.
通过错误信息,我们可以知道有一种解决方案:就是在app
所在module
的AndroidManifest.xml
的application
节点里面配置一个属性tools:replace="android:name"
。这样就可以避免编译失败!
然后app
所在的清单文件配置如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.xxx.ddd">
<application
android:name=".base.BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:name"
>
<!---->
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
关键的就是一行
tools:replace="android:name"