【问题标题】:ERROR: Manifest merger failed : Attribute application@appComponentFactory错误:清单合并失败:属性 application@appComponentFactory
【发布时间】:2019-11-19 00:25:12
【问题描述】:

我在 Android Studio 中有一个 with gradle build 问题。当我在项目中添加 Admob Activity 时,在将依赖项添加到项目时会引发两个错误

  1. ERROR: Manifest merger failed

  2. org.gradle.execution.MultipleBuildFailures:构建完成,有 1 次失败 对于第一个问题,它建议像“建议:将 'tools:replace="android:appComponentFactory"' 添加到 AndroidManifest.xml:10:5-32:19 的元素以覆盖。 "

即使添加工具后:replace="android:appComponentFactory" 到 Androidmanifest gradle 同步失败

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"

【问题讨论】:

    标签: android-studio gradle android-gradle-plugin build.gradle android-manifest


    【解决方案1】:

    我有类似的问题。在gradle.properties 文件中添加了两行:

    android.useAndroidX=true

    android.enableJetifier=true

    这两行自动解决了我在谷歌文件和第三方依赖之间的依赖冲突。

    【讨论】:

      【解决方案2】:

      通过将googlePlayServicesVersion = "16.+" 添加到app/build.gradle 来查找解决方案,因为Google 服务 已更新:

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

      【讨论】:

        猜你喜欢
        • 2019-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多