来自androidx和com.android.support的重复类

问题描述 投票:17回答:2

我最近更新了我的Android Studio(我很确定Gradle版本),现在我在尝试编译项目时遇到了一堆错误。这是目前困扰我的那个:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:26.1.0)

接下来是许多类似的。

我尝试删除com.android.support的所有用途,转而使用androidx(请参阅here我使用的替换内容),但com.android.support库仍在使用,即使我删除了库(它们只是在我再次尝试编译时重新创建) )。

Here's链接到我得到的完整错误。

android android-studio android-gradle libraries androidx
2个回答
42
投票

我希望你在gradle.properties这两行:

(如果你没有gradle.properties,那么只需在项目的根目录中创建它)

android.useAndroidX=true
android.enableJetifier=true

看起来你有一些support遗物任何在你的依赖,可能形成一个lib?要调查并查看依赖项树,请运行

./gradlew :yourApp:dependencies

然后你会看到它来自哪里。


4
投票

在您的应用程序build.gradle中,您使用的是旧的支持库和新的支持库工件。从build.gradle中删除其中一个以解决此问题。

老神器:com.android.support:support-compat

相应的新神器:androidx.core:core:1.0.0

this page for more information on migrating to AndroidX

© www.soinside.com 2019 - 2024. All rights reserved.