此文章发布于64
个月前,部分信息可能已经过时
,请自行斟酌确认。
最近将 Android Studio
升级到3.5
版本后打开以前的项目并升级了 Gradle 后报错如下
Duplicate class android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$Delegate found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$DelegateProvider found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActionBarDrawerToggle$SlideDrawable found in modules classes.jar (com.android.support:support-core-ui:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActivityCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActivityCompat$SharedElementCallback21Impl found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActivityManagerCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.ActivityOptionsCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.BackStackRecord found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.BackStackRecord$Op found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.BackStackState found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.BackStackState$1 found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.DialogFragment found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.Fragment found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.Fragment$1 found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.Fragment$InstantiationException found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
Duplicate class android.support.v4.app.Fragment$SavedState found in modules classes.jar (com.android.support:support-fragment:28.0.0) and classes.jar (com.android.support:support-v4:22.0.0)
解决方案
在gradle.properties
中添加下面两行代码以选择androidX
作为您的支持库
android.useAndroidX=true
android.enableJetifier=true
本来就有这两行代码