我的项目运行良好,没有在我的应用程序中实现ViewPager2 gradle。但是当我在项目中使用gradle implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha01'时,它给了我这个Log-cat错误...

Android resource linking failed
Output:  D:\sam\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
D:\sam\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
D:\sam\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:557: error: resource android:attr/fontVariationSettings not found.
D:\sam\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:557: error: resource android:attr/ttcIndex not found.
D:\sam\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:834: error: resource android:attr/textFontWeight not found.
error: failed linking references.

Command: C:\Users\anonymous\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\e2e18b400b8fa36a8523d44c560bb82c\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
        C:\Users\anonymous\AppData\Local\Android\Sdk\platforms\android-27\android.jar\
        --manifest\
        D:\sam\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
        -o\
        D:\sam\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
        -R\
        @D:\sam\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
        --auto-add-overlay\
        --java\
        D:\sam\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
        --custom-package\
        com.sam.test.sushil\
        -0\
        apk\
        --output-text-symbols\
        D:\sam\app\build\intermediates\symbols\debug\R.txt\
        --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0


与此implementation group: 'androidx.viewpager2', name:'viewpager2', version: '1.0.0-alpha01'相同的错误

然后我创建了另一个空项目并实现了implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha01'

它给了我这个错误.....

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.1.0-alpha04] 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.


在特定于错误的上方,在android.support.v4.app.CoreComponentFactoryimplementation 'com.android.support:appcompat-v7:28.0.0'之间存在冲突。所以我从项目中删除了implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha01'库。

现在正在工作。

我的问题是

如果删除support:appcompat,则无法使用AppCompatActivity及其用途。这存在于我现有的应用程序中。

如何解决呢?

如何同时使用support:appcompatViewPager2

编辑

在清单的support:appcompat标记内添加tools:replace="android:appComponentFactory"后,@ ManoharReddy。它给我这个错误

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.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    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

最佳答案

我找到了解决方案。

正如@Kishore和@Shweta告诉您的,在项目中迁移AndroidX是解决方案。

手动添加android.useAndroidX=trueandroid.enableJetifier=true给了我很多时间。因为它抛出了一些错误或Suggestion: add 'tools:replace="android:appComponentFactory"' to <application>

要在项目中启用Jet-fire,android Studio中有一个选项

选择您的项目--->右键单击

app ---->重构---->迁移到AndroidX

如下图所示:

android - 使用androidX在项目中的ViewPager2配置-LMLPHP

单击“迁移到AndroidX”后。

它将要求您确认并备份您的项目。

android - 使用androidX在项目中的ViewPager2配置-LMLPHP

最后一步,它将要求您进行重构。

android - 使用androidX在项目中的ViewPager2配置-LMLPHP

完成重构后,检查gradle.properties是否具有android.useAndroidX=trueandroid.enableJetifier=true。如果不是,则将这两行添加到gradle.properties文件中:

android.useAndroidX=true
android.enableJetifier=true


感谢所有用户的帮助。

10-08 13:56