清单合并失败:属性 application@appComponentFactory - Androidx [英] Manifest merger failed : Attribute application@appComponentFactory - Androidx

查看:24
本文介绍了清单合并失败:属性 application@appComponentFactory - Androidx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 androidx 构建 Gradle 时,出现以下错误.请帮我解决这个问题.

When I'm building Gradle with androidx I get the following error. Please help me to solve this issue.

错误消息:清单合并失败:属性应用程序@appComponentFactory值=(android.support.v4.app.CoreComponentFactory) 来自[com.android.support:support-compat:28.0.0]AndroidManifest.xml:22:18-91 也存在于[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86value=(androidx.core.app.CoreComponentFactory).

Error Message: 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).

清单:

<?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.kanwarpreet.dealmybook">

    <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=".activities.SplashActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".activities.LoginActivity" />
        <activity android:name=".activities.RegisterActivity" />
        <activity
            android:name=".activities.HomeActivity"
            android:label="@string/title_activity_home"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".activities.BookDetailsActivity"
            android:label="@string/title_activity_book_details"
            android:theme="@style/AppTheme.NoActionBar"/>
        <activity android:name=".activities.AddBookActivity" />
    </application>

</manifest>

Build.Gradle:

Build.Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.kanwarpreet.dealmybook"
        minSdkVersion 21
        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.android.support:support-v4:28.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.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'
}

推荐答案

经过几个小时的挣扎,我通过在 app/build.gradle 中包含以下内容解决了这个问题:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

将这些标志放在你的 gradle.properties 中

Put these flags in your gradle.properties

android.enableJetifier=true
android.useAndroidX=true

build.gradle 的变化:

Changes in build.gradle:

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha04'

参考:https://developer.android.com/jetpack/androidx/migrate

这篇关于清单合并失败:属性 application@appComponentFactory - Androidx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆