How to fix duplicate libraries - more than one lib

2019-05-14 00:53发布

问题:

Gradle build error - more than one library with package name android.support.v7.appcompat. This project has Chrome Cast in it, so is using android-support-v7-appcompat and CastCompanionLibary-android-master. Project structure is the following:

  • BaseGameUtils
  • CastCompanionLibrary-android-master
  • VideoBrowserActivity
  • android-support-v7-appcompat
  • android-support-v7-mediarouter
  • google-play-services_lib

Really tough error because the compiler doesn't give much information other than 'more than one library with package name 'android.support.v7.appcompat'. Understand why you don't want to be using different versions of the same library, but why doesn't the compiler reveal what versions are being used, and where they are being called from?

Trying to add leaderboard similar to type-a-number challenge (github example project)

There are a total of (7) build.gradle files. One for the top level and one for each of the packages listed above. Top level gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {

repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.0.0'
}

BaseGameUtils:

dependencies {
    compile 'com.android.support:appcompat-v7:20.0.+'
    compile 'com.android.support:support-v4:20.0.+'
    compile 'com.google.android.gms:play-services-games:6.5+'
    compile 'com.google.android.gms:play-services-plus:6.5+'
    compile 'com.google.android.gms:play-services-appstate:6.5+'
}

CastCompanionLibrary-android-master

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:appcompat-v7:20.0.+'
    compile project(':android-support-v7-mediarouter')
    compile 'com.google.android.gms:play-services-cast:6.5+'
    compile project(':BaseGameUtils')
}

VideoBrowserActivity

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':CastCompanionLibrary-android-master')
}

android-support-v7-appcompat

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android-support-v7-mediarouter

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':android-support-v7-appcompat')
}

google-play-services_lib

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

Any help is appreciated on this.

回答1:

Just go through you project's libs folder not from the Android Studio but from you windows explorer/finder (for windows)/(for mac). And search for android.support.v7.appcompat. Any evidence found related to Apcompat (whether it is v4 or v7) is recommended to be deleted.

Hopefully your problem will be solved.

In your libs folder dont miss any sub directory that has libs folder.