Android 開發之v4庫沖突問題解決方案說明
阿新 • • 發佈:2019-04-25
per 內容 The found ict 通過 播放 app play
問題背景
Android Studio 開發時使用到了 GSYVideoPlayer 開源的播放器框架,配置信息如下:
implementation ‘com.shuyu:GSYVideoPlayer:6.0.1‘
在這之前,已經配置了support庫:
implementation ‘com.android.support:appcompat-v7:28.0.0‘
運行時報錯如下:
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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) 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.2.1) ... Duplicate class android.support.v4.app.NotificationBuilderWithBuilderAccessor found in modules classes.jar (com.android.support:support-compat:28.0.0) and internal_impl-22.2.1.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$Action found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$Action$Builder found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$Action$Extender found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$Action$WearableExtender found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$BigPictureStyle found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$BigTextStyle found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$Builder found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$CarExtender found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$CarExtender$UnreadConversation found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$CarExtender$UnreadConversation$Builder found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$Extender found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$InboxStyle found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$Style found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompat$WearableExtender found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompatExtras found in modules classes.jar (com.android.support:support-compat:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.app.NotificationCompatJellybean found in modules classes.jar (com.android.support:support-compat:28.0.0) and internal_impl-22.2.1.jar (com.android.support:support-v4:22.2.1) ... Duplicate class android.support.v4.widget.ViewDragHelper$1 found in modules classes.jar (com.android.support:customview:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.widget.ViewDragHelper$2 found in modules classes.jar (com.android.support:customview:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Duplicate class android.support.v4.widget.ViewDragHelper$Callback found in modules classes.jar (com.android.support:customview:28.0.0) and classes.jar (com.android.support:support-v4:22.2.1) Go to the documentation to learn how to Fix dependency resolution errors.
通過報錯的內容大概可以猜測出來是播放器使用的V4庫和我們配置的V4庫出現沖突了,而且是版本沖突。
解決方案
解決方案無非就是移除項目中的 support-v4 或者 GSYVideoPlayer 中的 support-v4 來保持唯一性。
方案1:移除項目中的support-v4
缺點:項目無法使用 support-v4 下的 API
compile(‘com.android.support:appcompat-v7:23.3.0‘) { exclude group: "com.android.support", module: "support-v4" }
方案2:移除 GSYVideoPlayer 中的 support-v4
優點:不影響項目使用 support-v4
缺點:如果項目涉及到多個開源框架出現此問題要在開源框架下個個移除
implementation (‘com.shuyu:GSYVideoPlayer:6.0.1‘) {
exclude module: ‘support-v4‘
exclude group: ‘com.android.support‘
}
一般情況下,我們選擇第二種方式來解決沖突,這樣更可控一些。
Android 開發之v4庫沖突問題解決方案說明