【问题标题】:Manifest merger failed : Attribute application@appComponentFactory Google Play services [duplicate]清单合并失败:属性 application@appComponentFactory Google Play 服务 [重复]
【发布时间】:2019-09-06 22:25:40
【问题描述】:

一旦我实施 gplay 服务,我就会在一个空项目上立即发生冲突。

在 mac 上最新的 android studio 上,我创建了一个简单的活动应用程序: 主要活动:

package semy.apps.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

然后一旦我在build.gradle上添加实现'com.google.android.gms:play-services-ads:18.1.1'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.android.gms:play-services-ads:18.1.1'

}

我明白了

ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-19:19 to override.

我尝试在清单上添加这些标签无济于事,仍然不起作用

【问题讨论】:

    标签: android google-play-services


    【解决方案1】:

    您的问题的快速解决方案可能是在您的 AndroidMannifest.xml 中添加以下 3 行

        xmlns:tools="http://schemas.android.com/tools"
        tools:replace="android:appComponentFactory"
        android:appComponentFactory="@string/app_name"
    

    所以,添加以上 3 行之后,您的 AndroidMannifest.xml 应该是这样的,

    AndroidMannifest.xml

        <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        ...
        <!--Add the following 3 lines-->
        <application
            xmlns:tools="http://schemas.android.com/tools"
            tools:replace="android:appComponentFactory"
            android:appComponentFactory="@string/app_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>
    

    编辑:将您的依赖项更新到最新版本,因为 play-services-ads 使用的是 androidx 版本的支持库,而您使用的是传统版本。

    build.gradle(模块:app)

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'androidx.appcompat:appcompat:1.0.2'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.google.android.gms:play-services-ads:18.2.0'
    }
    

    我希望它能修复您的构建错误。让我知道它是否有效?

    【讨论】:

    • 谢谢,但我在模块 classes.jar (androidx.core:core:1.0.0) 和 classes.jar (com. android.support:support-compat:28.0.0) 在模块 classes.jar (androidx.core:core:1.0.0) 和 classes.jar (com.android) 中找到重复的类 android.support.v4.app.INotificationSideChannel$Stub .support:support-compat:28.0.0) 在模块 classes.jar (androidx.core:core:1.0.0) 和 classes.jar (com. android.support:support-compat:28.0.0)
    • 我已经更新了我的答案。您可以尝试将依赖项更新到我建议的版本并查看它是否修复了吗?
    • @inrob 你能解决这个问题吗?如果是这样,请告诉我们,真正的原因是什么?您是如何解决的?
    • 谢谢你,我不在家,无法回复,但你解决了我的问题
    • 这是我的荣幸 :)
    猜你喜欢
    • 2019-08-08
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-02
    相关资源
    最近更新 更多