我在Android Studio中发布了gradle build。当我在项目中添加Admob Activity时,将依赖项添加到项目中时会抛出两个错误

  • ERROR: Manifest merger failed
  • org.gradle.execution.MultipleBuildFailures:构建完成,发生1次失败
    对于第一期,它建议像“建议:在AndroidManifest.xml:10:5-32:19的元素上添加'tools:replace =“android:appComponentFactory”“来覆盖。

  • 即使在添加工具之后:android.manifest gradle同步中的replace="android:appComponentFactory"也失败

    AndroidManifest:
    <?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.ani.admobcheck">
    
    <!-- Include required permissions for Google Mobile Ads to run. -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Ads"
            android:label="@string/title_activity_ads"></activity>
        <!-- Include the AdActivity configChanges and theme. -->
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
    
    
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiM    ode|screenSize|smallestScreenSize"
                android:theme="@android:style/Theme.Translucent" />
            <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>
    
    
    
        Build.gralde :
        apply plugin: 'com.android.application'
    
        android {
    
        compileSdkVersion 28
    
        defaultConfig {
    
            applicationId "com.ani.admobcheck"
    
            minSdkVersion 15
    
            targetSdkVersion 28
    
            versionCode 1
    
            versionName "1.0"
    
            testInstrumentationRunner
    
    "android.support.test.runner.AndroidJUnitRunner"
    
        }
    
        buildTypes {
    
            release {
    
                minifyEnabled false
    
                proguardFiles getDefaultProguardFile('proguard-android-
    
    optimize.txt'), 'proguard-rules.pro'
    
            }
    
        }
    }
    
    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'
        implementation 'com.google.android.gms:play-services-ads:18.0.0'
        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'
    }
    

    我收到同步错误为:
    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:10:5-32:19 to override.
    

    我尝试在AndroidManifest中添加tools:replace="android:appComponentFactory"

    最佳答案

    由于Google服务已更新,因此可以在googlePlayServicesVersion = "16.+"中添加app/build.gradle来找到解决方案:

    buildscript {
        ext {
            ...
            googlePlayServicesVersion = "16.+"
        }
        ...
    }
    

    10-07 18:18