清单合并失败错误(工具:替换=" android:launchMode")

时间:2018-04-13 00:07:35

标签: android xml gradle android-gradle android-manifest

我将Android Studio更新为3.1版,将Gradle for my Project更新为3.1.0版。 从那时起,我遇到了一些与合并多个文件有关的问题,但我能够解决。 然后我有这个错误:

> Manifest merger failed : 
Attribute activity#com.aware.ui.PermissionsHandler@launchMode 
value=(singleTop) from [com.awareframework:aware-core:4.0.555] 
AndroidManifest.xml:35:13-43 is also present at 
[com.github.denzilferreira:aware-client:4.0.555] 
AndroidManifest.xml:44:13-42 value=(standard).
Suggestion: add 'tools:replace="android:launchMode"' to <activity> 
element at AndroidManifest.xml:30:9-37:66 to override.

所以,首先我尝试在提到的Activity中使用tools:replace="android:launchMode"

<activity android:name=".MainActivity"
    ...
    tools:replace="android:launchMode"
    android:launchMode="standard">
</activity>

但它没有解决问题,然后我搜索并发现了一些类似的问题和他们的回答。

其中一人说要从冲突的库中删除建议的属性:

<activity
    android:name="com.aware.ui.PermissionsHandler"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:excludeFromRecents="true"
    android:exported="true"
    android:launchMode="singleTop" //deleted this line from Manifests
    android:noHistory="true"
    android:theme="@style/Theme.AppCompat.Translucent" />

但同样,没有成功。我还尝试在应用程序标记中使用tools:replace="android:launchMode"

<application
    ...
    tools:replace="android:launchMode">

然后使用活动代码中的android:launchMode="standard"

<activity android:name=".MainActivity"
    ....
    android:launchMode="standard">
</activity>

但它引发了一个不同的错误:

tools:replace specified at line:16 for attribute android:launchMode, 
but no new value specified

我还尝试重新排序Gradle文件中的依赖项,例如@GLee回答here,但它没有任何区别。

这是我正在使用的图书馆之一:Aware Activity Recognition Plugin

这是我用来创建应用程序的教程:Creating a standalone application

另一个相关的事情是,两个依赖项冲突在不同的模块中,com.awareframework:aware-core:4.0.555依赖项位于app模块内,com.github.denzilferreira:aware-client:4.0.555位于activity_recognition模块内。

最后,这是我的App Gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "app.miti.com.iot_reduce_daily_stress_application"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    ...
}

dependencies {
    ...
    implementation "com.awareframework:aware-core:${aware_libs}"
    implementation "com.android.support:appcompat-v7:${support_libs}"
    implementation "com.android.support:cardview-v7:${support_libs}"
    implementation "com.google.android.gms:play-services-location:${gms_libs}"
    implementation "com.google.android.gms:play-services-maps:${gms_libs}"
    implementation "com.google.android.gms:play-services-places:${gms_libs}"
    implementation 'com.android.support:preference-v14:${support_libs}'
    implementation "com.android.support:design:${support_libs}"
    implementation 'pub.devrel:easypermissions:1.2.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.google.firebase:firebase-core:${firebase_libs}"
    implementation "com.google.firebase:firebase-messaging:${firebase_libs}"
    ...
}

这是我的activity_recognition模块Gradle文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode version_code
        versionName version_readable
        multiDexEnabled true
    }
    ...
}

dependencies {
    ...
    implementation "com.google.android.gms:play-services-location:${google_libs}"
    implementation "com.android.support:appcompat-v7:${support_libs}"
    api "com.github.denzilferreira:aware-client:${aware_libs}"
    implementation "com.koushikdutta.ion:ion:2.1.6"
    implementation "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2"
}

这是App AndroidManifest.xml(错误网址指向此文件):

<?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="app.miti.com.iot_reduce_daily_stress_application">

    ... //permissions

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name="android.support.multidex.MultiDexApplication">

        <activity android:name=".MainActivity"
            android:configChanges="keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".SettingsActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:parentActivityName=".MainActivity"
            tools:ignore="UnusedAttribute">
        </activity>

    </application>

</manifest>

由于这不是依赖版本问题,就像我发现的许多其他问题一样,并且因为我必须在我的Project中使用这个库依赖项,我该如何解决这个问题?

P.S:我已经尝试过常用的方法:

  • 使缓存无效/重新启动
  • 已删除Gradle
  • 清理项目并重建项目
  • ...

1 个答案:

答案 0 :(得分:1)

问题在于com.aware.ui.PermissionsHandler,这就是为什么在.MainActivity上放置属性无济于事,因为这是一项不同的活动。由于您在发布的Gradle文件中使用工件,我不确定您在哪里修改库的清单。

在你的应用清单中,添加:

<activity
  android:name="com.aware.ui.PermissionsHandler"
  android:launchMode="..."
  tools:replace="android:launchMode"
/>

其中...是您期望的launchMode值,可能是在与这些库的开发人员进行一些讨论之后确定正确的答案。

您不应该需要任何其他属性或子元素 - 它们都应该通过清单合并过程合并进来。

相关问题