尝试实现库时,如何解决清单合并失败的错误?

时间:2019-06-21 04:30:37

标签: java android

我正在尝试在Android上添加流氓纸,并遇到以下问题

在我的应用程序gradle中,我有这个

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.ramotion.paperonboarding:paper-onboarding:1.1.3'

但我收到此错误

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.1] 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.

2 个答案:

答案 0 :(得分:1)

我希望这对您有用

您必须将android.support迁移到androidx才能使用com.google.android.material.libraries

android.useAndroidX=true
android.enableJetifier=true

在gradle.properties文件中添加以上行。

通过以下方式迁移到Android X

转到重构--->迁移到AndroidX --->单击“迁移”按钮,然后执行折射。

并从androidx包中导入您的类和XML。

例如

活动:

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

答案 1 :(得分:0)

我认为您的库使用的是androidx,并且与您当前的项目具有相同的依赖项(您的项目使用的是旧的依赖项,这意味着androidX之前的依赖项)。当它尝试合并时,将引发冲突,因为它具有来自相同依赖项的不同来源。我建议将您对项目的依赖关系更新为Androidx:)