android:多module时,多 Application编译失败的问题解决

  1. 如果在app module中新建一个类public class BaseApplication extends Application {...}
  2. 然后在lib所在module中也新建一个类public class LibApplication extends Application {...}
  3. 并且在各自的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所在moduleAndroidManifest.xmlapplication节点里面配置一个属性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"

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值