清单合并失败:属性 application@appComponentFactory Google 播放服务

Manifest merger failed : Attribute application@appComponentFactory Google Play services

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

在 mac 的最新 android 工作室中,我创建了一个简单的 activity 应用程序: 主要activity:

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.

我尝试在清单上添加这些标签,但无济于事,仍然无效

您的问题的快速解决方案可能是在 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>

EDIT: Update your dependencies to the latest version as play-services-ads is using androidx version of support library and you are using the traditional one.

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'
}

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