AndroidX与Android Support包不兼容问题的解决方式

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 element at AndroidManifest.xml:6:5-22:19 to override.

  • 解决方案一

    在manifest 标签下加入xmlns:tools="http://schemas.android.com/tools" 在application标签下 加入tools:replace="android:appComponentFactory" android:appComponentFactory="whateverString" 重新build就可以了。

  • 解决方案二
    踩坑

  • 根据提示加入tools:replace="android:appComponentFactory" 重新build

  • 接着报错

    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugManifest'.
                    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
                    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
                    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
                    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
                    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
                    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
                    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
                    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
                    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
                    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
                    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
                    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
                    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
                    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
                    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
                    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
                    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
                    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
                    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
                    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
                    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
                    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
                    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
                    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
                    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
                    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
                    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
                    at java.lang.Thread.run(Thread.java:745)
                Caused by: java.lang.RuntimeException: Manifest merger failed with multiple errors, see logs
                    at com.android.builder.core.AndroidBuilder.mergeManifestsForApplication(AndroidBuilder.java:540)
                    at com.android.build.gradle.tasks.MergeManifests.doFullTaskAction(MergeManifests.java:173)
                    at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:106)
                    at sun.reflect.GeneratedMethodAccessor243.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                    at java.lang.reflect.Method.invoke(Method.java:498)
                    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
                    at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
                    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
                    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
                    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
                    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
                    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
                    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
                    ... 33 more
  • 然后我使用 ./gradlew app:processDebugManifest 命令查看具体信息
  > Task :app:processDebugManifest FAILED
                    /Users/zhangqi/MyMaterial/AndroidProject/WanAndroid_Qi/app/src/main/AndroidManifest.xml:6:5-23:19 Error:
                            tools:replace specified at line:6 for attribute android:appComponentFactory, but no new value specified
                    /Users/zhangqi/MyMaterial/AndroidProject/WanAndroid_Qi/app/src/main/AndroidManifest.xml Error:
                            Validation failed, exiting
                    
                    See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
1. 看到这个提示信息,然后又添加adnroid:appComponentFactory="android.support.v4.app.CoreComponentFactory",重新Rebuild
  • 又报错了,然后我又Google了一会说是 Androidx和Android Support库不能共存,吓得我立马看了下依赖库,确实有AndroidX,接下来就谈谈这个

解决办法

  • 转换成AndroidX

    1. 更新文件

    将buildTools 更新到3.2.0 gradle 更新到4.6 依赖库统一更新到28.0.0 这一步影响这个第二部的进行

        * compileSDKVersion 28
    
        *  implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'
      implementation 'com.android.support:recyclerview-v7:28.0.0'
    
        *  dependencies {
          classpath 'com.android.tools.build:gradle:3.2.0'
          }
    
        *  distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
    
    1. 进行转换,将Android Support 转换成AdnroidX
      1. 右键项目文件 选择 refactor -> Migrate to AdnroidX 。


        AndroidX与Android Support包不兼容问题的解决方式_第1张图片
        Support2Androidx.jpg
      2. 然后就进行转换,然后选择doRefactor 最后执行完成后,再去看依赖,发现全部Support转换成AndroidX。
  • 将依赖中的AndroidX转换成AndroidSupport

    1. 查看依赖中都有那些引用了AndroidX,然后给回退到没有AndroidX的版本中。

      运行命令 ./gradlew :app:dependencies 查看包依赖详情信息

      AndroidX与Android Support包不兼容问题的解决方式_第2张图片
      SearchAdnroidX.jpg

      发现 是ButterKnife当前版本中有AdnroidX,当前它的版本shi 10.1.0 ,然后我给回退到8.1.0 后重新 rebuild,发现成功了,项目也能运行了。

小结

这里说下,当我是用解决方案一的时候,虽然build成功了,但是在部署项目到真机上的时候,还是报错了,所以这里推荐使用方案二中的两个方法,如果项目单纯是第三方依赖中需要AdnroidX,我们可以回退到没有AndroidX的版本中。

你可能感兴趣的:(AndroidX与Android Support包不兼容问题的解决方式)