【问题标题】:Manifest merger failed, error on compiling清单合并失败,编译时出错
【发布时间】:2018-10-23 12:18:08
【问题描述】:

由于下载了最新的 SDK 并安装了 Android Studio,我的项目构建失败。 我收到以下消息:

清单合并失败并出现多个错误


我的 gradle 应用程序:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.clupascu.oavm"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.github.chrisbanes:PhotoView:2.2.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'
}

我的清单

<?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.app.clupascu.oavm">

    <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"
        tools:ignore="GoogleAppIndexingWarning"
        tools:replace="android:appComponentFactory">

        <activity
            android:name=".MainPage"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name=".FirstObchodni"
            android:label="@string/obchodn_akademie"/>

        <activity android:name=".SecondObchodni"
            android:label="@string/_2_obchodn_akademie"/>

        <activity android:name=".VysiiOdborna"
            android:label="@string/_3_vy_odborn_kola"/>
    </application>

</manifest>

在合并清单中是这样写的:

Merging Errors: Error: tools:replace specified at line:6 for attribute android:appComponentFactory, but no new value specified app main manifest (this file), line 5 Error: Validation failed, exiting app main manifest (this file) 

我尝试了很多其他问题的解决方案,但没有结果,非常感谢。

【问题讨论】:

标签: java android gradle manifest


【解决方案1】:

在我的应用程序中实现地图 API 时,我遇到了同样的情况。 我通过在 AndroidManifest.xml 和 Gradle.properties 文件中添加以下代码来解决它。

在 AndroidMainfest.xml 中 添加此代码

    android:appComponentFactory="androidx.core.app.CoreComponentFactory"
    tools:replace="android:appComponentFactory"

在 gradle.properties 中添加了这段代码

   android.useAndroidX=true
   android.enableJetifier=true

【讨论】:

  • 我需要启用 AndroidX 但要禁用 jetifier
【解决方案2】:

"tools:replace="android:appComponentFactory"

  1. 删除工具:replace="android:appComponentFactory"

  2. 为 android:appComponentFactory" 属性提供新值

希望对你有帮助。

【讨论】:

  • 我删除了 tools:replace="android:appComponentFactory" 并且出现了另一个 Manifest 错误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 &lt;application&gt; element at AndroidManifest.xml:6:5-34:19 to override.
  • 你应该选择一个女巫来使用。清单合并告诉您,此属性有两个可能的值来自您正在使用的库。
  • 你能告诉我怎么做吗?
  • 回答您的问题添加 android:appComponentFactory="androidx.core.app.CoreComponentFactory"。但这只是一个症状,您的项目似乎同时依赖于支持库和 jetpack 库,您确定要这样做吗?
  • @simpller 你能说说你是怎么解决这个问题的吗?
猜你喜欢
  • 2017-05-12
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-22
  • 2020-01-10
  • 1970-01-01
相关资源
最近更新 更多